Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Last active December 22, 2025 23:46
Show Gist options
  • Select an option

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

Select an option

Save goofballLogic/a786df53be79acff9fe2d4079927aeab to your computer and use it in GitHub Desktop.
/* solution */
const validate = ([y, z, ...rest]) =>
rest.length
? (rest.shift() === y && validate([z, y, ...rest]))
: true;
/* testing */
function assert(input, expected) {
const actual = validate(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