Files
factorio-clusterio/lib/stringUtils.js
T
Hornwitser 0d4ad2f075 Fix global leaks detected by mocha
Fix globals leaked in stringUtils, isJson and static/nav.html.
2019-08-24 11:02:50 +02:00

13 lines
360 B
JavaScript

function hashCode(string){
if(typeof string !== "string") throw "ERROR stringUtils: Not a string";
var hash = 0;
if (string.length == 0) return hash;
for (let i = 0; i < string.length; i++) {
hash = ((hash << 5) - hash) + string.charCodeAt(i);
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
module.exports = {
hashCode: hashCode,
}