Skip to content

Instantly share code, notes, and snippets.

@eugeneglova
Last active August 25, 2017 06:33
Show Gist options
  • Save eugeneglova/69aba8adfeef522f75e6c7f4c5f2b69c to your computer and use it in GitHub Desktop.
Save eugeneglova/69aba8adfeef522f75e6c7f4c5f2b69c to your computer and use it in GitHub Desktop.
find missing
var list = [1, 3, 5, 2, 6, 7, 9, 4];
list.sort();
function find(list, acc = 0) {
if (list.length < 3 && list[1] - list[0] !== 1) return list[0] + 1;
const n = Math.round(list.length / 2);
const n1 = acc + n;
const realN = list[n - 1];
return find(n1 * (n1 + 1) === realN * (realN + 1) ? list.slice(n - (list.length % 2 === 0 ? 0 : 1)) : list.slice(0, n), n1);
}
find(list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment