Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

On Line 5, I wanted to convert key+1 from a string to a number without using the JavaScript functions parseInt() or parseFloat(). I tried to do the conversion but it took about 4 or 5 additional lines of code. I wanted to do it inline, with 1 or 2 additional lines.

However, since I'm OK with having float being returned from the hash function, is it safe if I just left key+1 as a string?

var hashString = function(S, alpha, tblSize) {
    var rawValue = 0;
    var modValue = 0;
    Object.keys(S).forEach(function (key) {
        rawValue = rawValue + (Math.pow(alpha, (S.length - (key+1))) * S[key].charCodeAt(0));
    });
    modValue = rawValue % tblSize;

    return [rawValue, modValue];
}
share|improve this question

put on hold as off-topic by Jamal 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.

    
key+1 is probably a string. –  wvxvw 2 days ago