Skip to content

Instantly share code, notes, and snippets.

@mendes5
Last active May 8, 2018 13:27
Show Gist options
  • Select an option

  • Save mendes5/1063326a25ba098a396014f8b3cd9ee7 to your computer and use it in GitHub Desktop.

Select an option

Save mendes5/1063326a25ba098a396014f8b3cd9ee7 to your computer and use it in GitHub Desktop.
Did thanos kill you?
/*
* Blazing fast!
* Case insensitive
* You can check your friends too!
* Not Math.random() based
* Same answers:
- any device (i think...)
- any time
- any place
- any universe
*/
const checksum = (s) => s.trim().toLowerCase().replace(/\s/g, '').split("").reduce((a, b) => {
a = ((a << 5) - a) + b.charCodeAt(0);
return a & a
}, 0);
const didThanosKillYou = name => (checksum(name) % 2)
? "You were slain by Thanos, for the good of the Universe."
: "You were spared by Thanos.";
/*
//Usage:
const name = prompt('Enter your name:');
alert(didThanosKillYou(name));
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment