Last active
February 12, 2020 22:16
-
-
Save Mk-Etlinger/84afc113c2c04fe51a629ea2314de709 to your computer and use it in GitHub Desktop.
Hacker Rank - pairSum v2
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 pairSum(data, target) { | |
let sumMatchesTarget; | |
data.forEach((currentNumber, index) => { | |
if (sumMatchesTarget) { return; } | |
const dataFiltered = removeCurrentIndex(data, index); | |
sumMatchesTarget = dataFiltered.some(nextNumber => { | |
const sum = (currentNumber + nextNumber); | |
return sum === target; | |
}) | |
}) | |
return sumMatchesTarget; | |
} | |
function removeCurrentIndex(data, index) { | |
return data.filter((_, i) => i !== index); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment