Skip to content

Instantly share code, notes, and snippets.

@converge
Created January 20, 2019 15:11
Show Gist options
  • Select an option

  • Save converge/760bb4bd2b4579ebf5af42ac549631c2 to your computer and use it in GitHub Desktop.

Select an option

Save converge/760bb4bd2b4579ebf5af42ac549631c2 to your computer and use it in GitHub Desktop.
function solution(A) {
// permutation -> if numbers in sequences, return 1
// ex. [3,1,2] is a permutation, [3,4,1] isn't
let result = 1
let sortedArr = A.sort((a,b) => a - b)
let next = sortedArr[0]
for (let i=0; i < sortedArr.length; i++) {
(sortedArr[i] !== next) ? result = 0 : next += 1
}
return result
}
A = [1,2,3]
console.log(solution(A))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment