Created
January 20, 2019 15:11
-
-
Save converge/760bb4bd2b4579ebf5af42ac549631c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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