Skip to content

Instantly share code, notes, and snippets.

@conor909
Created August 21, 2019 17:23
Show Gist options
  • Save conor909/357982780548d5a5bf7746333156493f to your computer and use it in GitHub Desktop.
Save conor909/357982780548d5a5bf7746333156493f to your computer and use it in GitHub Desktop.
Find next non incremented number greater then 0
// find next non incremented number greater then 0
function solution(array) {
const sortedArray = array.sort((a, b) => (a - b));
const cleanArray = [...new Set(sortedArray)];
const N = cleanArray.reduce((total, value, i, arr) => {
if (value !== total + 1) {
const n = value + 1
return n > 0 ? n : 1
}
return total
}, 0);
return N
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment