I tried to create a hash function in Javascript, and I noticed that one version of it had strange behavior with two-letter strings.
function hash(seed) {
var genseed = 0;
for(i=0;i<seed.length;++i) {
genseed += seed.charCodeAt(i)**((seed.length-1)-i);
}
console.log(genseed)
}
When you call hash on two-letter strings like hash("AB") and hash("AX"), you get the exact same result. Yes I know about hash collision, but here it seems that so long as the first letter is the same, the second letter changes nothing, so is it just being ignored? Why exactly does this happen?
(seed.length-1)-i?**iinstead of the more complicated formula?