Created
February 17, 2019 07:45
-
-
Save Vigowebs/9bc448f636e47bafdc92119ca0988f1e to your computer and use it in GitHub Desktop.
This file contains 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 sumFinder(arr, sum){ | |
var differ = {}, | |
len = arr.length, | |
substract; | |
for(var i =0; i<len; i++){ | |
substract = sum - arr[i]; | |
if(differ[substract]) | |
return true; | |
else | |
differ[arr[i]] = true; | |
} | |
return false; | |
} | |
sumFinder([6,4,3,2,1,7], 9); | |
// true | |
sumFinder([6,4,3,2,1,7], 2); | |
// false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment