hash.js 375 B

12345678910111213
  1. /**
  2. * Simple hash function by bryc
  3. * https://gist.github.com/iperelivskiy/4110988#gistcomment-2697447
  4. */
  5. function hash(s) {
  6. let h = 0xdeadbeef;
  7. for (let i = 0; i < s.length; i++) {
  8. h = Math.imul(h ^ s.charCodeAt(i), 2654435761); // eslint-disable-line no-bitwise
  9. }
  10. return (h ^ (h >>> 16)) >>> 0; // eslint-disable-line no-bitwise
  11. }
  12. module.exports = { hash };