Skip to content

Instantly share code, notes, and snippets.

@thomasvaeth
Last active October 28, 2019 17:04
Show Gist options
  • Save thomasvaeth/a02beebedf5befa27b6b2429a6cef11e to your computer and use it in GitHub Desktop.
Save thomasvaeth/a02beebedf5befa27b6b2429a6cef11e to your computer and use it in GitHub Desktop.
"The successful warrior is the average man, with laser-like focus." - Bruce Lee
function missingInts(arr) {
if (arr.length < 2) return [];
const missingNums = [];
const set = new Set(arr);
for (let i = 1; i < arr[arr.length - 1]; i++) {
if (!set.has(i)) missingNums.push(i);
}
return missingNums;
}
missingInts([1, 3, 3, 3, 5, 6]);
missingInts([1, 2, 3, 4, 4, 7, 7]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment