Created
December 22, 2025 21:28
-
-
Save goofballLogic/f5add5e4f25f28bda95a652a25dae42d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* solution */ | |
| function process([y, z, ...rest] = []) { | |
| while (rest.length) { | |
| if (rest.shift() !== y) return false; | |
| [z, y] = [y, z]; | |
| } | |
| return true; | |
| } | |
| /* testing */ | |
| function assert(input, expected) { | |
| const actual = process(input); | |
| if (actual !== expected) | |
| console.error("FAIL", input, "(expected", expected, ")"); | |
| else | |
| console.log("PASS", input); | |
| } | |
| assert([], true); | |
| assert([1], true); | |
| assert([1,1], true); | |
| assert([1,2,1], true); | |
| assert([10,5,10,5,10], true); | |
| assert([2,2,3,3], false); | |
| assert([5,4,3,5,4,3], false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment