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];
}
key+1
is probably a string. – wvxvw 2 days ago