Skip to content

Instantly share code, notes, and snippets.

@MartinSeeler
Created October 2, 2015 10:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MartinSeeler/f89ddcae1e5fbf729d92 to your computer and use it in GitHub Desktop.
Save MartinSeeler/f89ddcae1e5fbf729d92 to your computer and use it in GitHub Desktop.
Konami Cheat-Code with RxJs
var cheatCode = [38,38,40,40,37,39,37,39,66,65]; // Konami Cheat Code
Rx.Observable
.fromEvent(document, 'keydown')
.map(function(x) { return x.keyCode; })
.windowWithCount(cheatCode.length, 1)
.flatMap(function(xs) { return xs.toArray(); })
.do(function (x) { console.log(x); })
.filter(function(xs) { return _.isEqual(cheatCode, xs); })
.subscribe(function(x) { console.log('CHEATER!!11elf'); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment