Created
August 2, 2015 10:31
-
-
Save k-hamada/22eb82fc42948abafa2e to your computer and use it in GitHub Desktop.
KonamiCode in Rx
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
| const CONAMI = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]; | |
| let array_equal = (arr1, arr2) => JSON.stringify(arr1) === JSON.stringify(arr2); | |
| Kefir | |
| .fromEvents(document, 'keydown') | |
| .map((ev) => ev.keyCode) | |
| .slidingWindow(CONAMI.length, CONAMI.length) | |
| .filter((keycodes) => array_equal(keycodes, CONAMI)) | |
| .onValue((keycodes) => alert('Konami Code')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment