Skip to content

Instantly share code, notes, and snippets.

@michalbe
Last active August 29, 2015 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalbe/5a4920ce840d0a669c05 to your computer and use it in GitHub Desktop.
Save michalbe/5a4920ce840d0a669c05 to your computer and use it in GitHub Desktop.
String.prototype.customHash = function(x) {
x = x || 10;
var sum = 0;
for (var i = 0, l=this.length; i<l; i++) {
sum += (this.charCodeAt(i) * i);
}
return (sum%x) + 1;
}
"info@prezydent.pl".customHash(10); // gdzie argument to Twoje x ze zdania 'od 1 do x'
"michal@github.com".customHash(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment