Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Created December 22, 2025 21:28
Show Gist options
  • Select an option

  • Save goofballLogic/f5add5e4f25f28bda95a652a25dae42d to your computer and use it in GitHub Desktop.

Select an option

Save goofballLogic/f5add5e4f25f28bda95a652a25dae42d to your computer and use it in GitHub Desktop.
/* 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