Skip to content

Instantly share code, notes, and snippets.

@k-hamada
Created August 2, 2015 10:31
Show Gist options
  • Select an option

  • Save k-hamada/22eb82fc42948abafa2e to your computer and use it in GitHub Desktop.

Select an option

Save k-hamada/22eb82fc42948abafa2e to your computer and use it in GitHub Desktop.
KonamiCode in Rx
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