Skip to content

Instantly share code, notes, and snippets.

@keevitaja
Created May 6, 2017 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keevitaja/7345756c74401ebb26fa0d1a9145e900 to your computer and use it in GitHub Desktop.
Save keevitaja/7345756c74401ebb26fa0d1a9145e900 to your computer and use it in GitHub Desktop.
Cheap hash for javascript
export default (s)=> {
let hash = 0
let strlen = s.length
if ( strlen === 0 ) {
return hash;
}
for (let i = 0; i < strlen; i++) {
let c = s.charCodeAt(i)
hash = ((hash << 5) - hash) + c
hash = hash & hash
}
return hash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment