Created
August 23, 2016 13:57
-
-
Save famousgarkin/4274ded50d05844c9c459db0524ec72f to your computer and use it in GitHub Desktop.
Codility - Lesson 3: Time Complexity - PermMissingElem (https://codility.com/programmers/task/perm_missing_elem/)
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) { | |
A.push(0) | |
return A.reduce(function(missing, value, i) { | |
return missing + i + 1 - value | |
}, 0) | |
} | |
var A = [] | |
A[0] = 2 | |
A[1] = 3 | |
A[2] = 1 | |
A[3] = 5 | |
var test = solution(A) | |
console.log(test, test === 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment