Created
September 8, 2017 18:10
-
-
Save juanigallo/c37bb54656c2b812915c843ca4f1279a to your computer and use it in GitHub Desktop.
Check sum of unordered array in JavaScript
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 checkUnorderedSum(arr, sum) { | |
let alreadySeen = []; | |
for (var i = 0; i < arr.length; i++) { | |
let complement = sum - arr[i]; | |
if (alreadySeen.indexOf(arr[i]) > -1) { | |
return true | |
} | |
alreadySeen.push(complement); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment