Created
October 2, 2015 10:39
-
-
Save MartinSeeler/f89ddcae1e5fbf729d92 to your computer and use it in GitHub Desktop.
Konami Cheat-Code with RxJs
This file contains 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
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