Last active
October 28, 2022 19:17
-
-
Save vsDizzy/713993f1ea5d26cee594a261053ce6b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function hash(s: string) { | |
return [].reduce.call(s, (p, c) => (p << 5) - p + c.charCodeAt(0), 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// so... in other words the following
export hash = s =>
[].reduce.call(s, (p, c) => (p << 5) - p + c.charCodeAt(0), 0);String.prototype.hash =
function() { return [].reduce.call(this,
(acc, el) => (acc << 5) - acc + el.charCodeAt(0), 0); };AKA String.prototype.hash = function() { return
Array.from(this).reduce(
(acc, el) => (acc << 5) - acc + el.charCodeAt(0), 0); };AKA String.prototype.hash = function() { return Array.from(this
, c => c.charCodeAt(0)
).reduce((acc, el) => (acc << 5) - acc + el, 0); };AKA String.prototype.hash = function() { return
[...this]
.reduce((n, c) => (n << 5) - n + c.charCodeAt(0), 0); };