Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andhikamaheva/367e44a7830b5349914228bd95ffd8bf to your computer and use it in GitHub Desktop.
Save andhikamaheva/367e44a7830b5349914228bd95ffd8bf to your computer and use it in GitHub Desktop.
Codility PerMissingElem Exercise Solution (JavaScript/NodeJS)
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
A.sort(function (a,b) {
return a - b
})
let result = 1
let i = 0
while (result === A[i]) {
result++
i++
}
return result
}
@mablook
Copy link

mablook commented Jan 28, 2020

function solution(A) {

A.sort(function (a,b) {
    return a - b
})

let result = 1;

for (x in A){
    if(result === A[x]){
        result = A[x] + 1;
    }
}
return result

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment