Skip to content

Instantly share code, notes, and snippets.

@fanweixiao
Forked from MartinSeeler/konami-cheatcode-rx.js
Created November 22, 2021 06:58
Show Gist options
  • Save fanweixiao/bef54340a9046a17631eba26d4de5a54 to your computer and use it in GitHub Desktop.
Save fanweixiao/bef54340a9046a17631eba26d4de5a54 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