Created
August 21, 2019 17:23
-
-
Save conor909/357982780548d5a5bf7746333156493f to your computer and use it in GitHub Desktop.
Find next non incremented number greater then 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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