Skip to content

Instantly share code, notes, and snippets.

@Vigowebs
Created February 17, 2019 07:45
Show Gist options
  • Save Vigowebs/9bc448f636e47bafdc92119ca0988f1e to your computer and use it in GitHub Desktop.
Save Vigowebs/9bc448f636e47bafdc92119ca0988f1e to your computer and use it in GitHub Desktop.
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