var numA = 123, numB = 123;
function hashCodeA(s) {
for(var i = 0, h = 0; i < s.length; i++)
h = Math.imul(31, h) + s.charCodeAt(i) | 0;
return h;
}
function hashCodeB(s) {
return [...s].reduce(
(hash, c) => (Math.imul(31, hash) + c.charCodeAt(0)) | 0,
0
);
}
hashCodeA("abcd" + numA); numA++;
hashCodeB("abcd" + numB); numB++;