Created
May 3, 2019 04:19
-
-
Save IAMIronmanSam/23e23757c088c01f0e75ef32831c7a3b to your computer and use it in GitHub Desktop.
Find possible sum pairs in array
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 toSum(numArray,sum){ | |
let pairs = []; | |
let hash = []; | |
for(let i = 0;i < numArray.length; i++){ | |
let counterPart = sum - numArray[i]; | |
if(hash.indexOf(counterPart) != -1){ | |
pairs.push([numArray[i],counterPart]); | |
} | |
hash.push(numArray[i]); | |
} | |
return pairs; | |
} | |
toSum([1,2,3,4,5,6],7); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment