Skip to content

Commit

Permalink
Clean up Konami code example
Browse files Browse the repository at this point in the history
  • Loading branch information
domfarolino committed Jun 6, 2024
1 parent 2a2f5a1 commit 6fc6b71
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,36 +214,33 @@ keys the user might hit while using an app:

```js
const pattern = [
'ArrowUp',
'ArrowUp',
'ArrowDown',
'ArrowDown',
'ArrowLeft',
'ArrowRight',
'ArrowLeft',
'ArrowRight',
'b',
'a',
'b',
'a',
'Enter',
'ArrowUp',
'ArrowUp',
'ArrowDown',
'ArrowDown',
'ArrowLeft',
'ArrowRight',
'ArrowLeft',
'ArrowRight',
'b',
'a',
'b',
'a',
'Enter',
];

const keys = document.on('keydown').map((e) => e.key);
const keys = document.on('keydown').map(e => e.key);

keys
.flatMap((firstKey) => {
if (firstKey === pattern[0]) {
return keys
.take(pattern.length - 1)
.every((k, i) => k === pattern[i + 1]);
}
})
.filter((matched) => matched)
.subscribe({
next: (_) => {
console.log('Secret code matched!');
},
});
.flatMap(firstKey => {
if (firstKey === pattern[0]) {
return keys
.take(pattern.length - 1)
.every((k, i) => k === pattern[i + 1]);
}
})
.filter(matched => matched)
.subscribe(() => console.log('Secret code matched!'));
```

<details>
Expand All @@ -265,10 +262,11 @@ document.addEventListener('keydown', e => {
console.log('Secret code matched!');
document.removeEventListener('keydown', handler)
}
}
document.addEventListener('keydown', handler)
};

document.addEventListener('keydown', handler);
}
})
}, {once: true});
```

</details>
Expand Down

0 comments on commit 6fc6b71

Please sign in to comment.