Skip to content

Instantly share code, notes, and snippets.

@jmillerdesign
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save jmillerdesign/43e17b40d1e439012dc5 to your computer and use it in GitHub Desktop.

Select an option

Save jmillerdesign/43e17b40d1e439012dc5 to your computer and use it in GitHub Desktop.
Convert any string into an integer
/**
* Convert any string into an integer
*
* @param {string} str Input string
* @return {integer} Integer
*/
var strToInt = (function () {
var map = {};
var size = 0;
var hash;
return function (str) {
hash = crypto.createHash('md5').update(str).digest('hex');
if (!map.hasOwnProperty(hash)) {
// Add new hash to the map
map[hash] = ++size;
}
return map[hash];
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment