Last active
May 8, 2018 13:27
-
-
Save mendes5/1063326a25ba098a396014f8b3cd9ee7 to your computer and use it in GitHub Desktop.
Did thanos kill you?
This file contains hidden or 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
| /* | |
| * 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