Skip to content

Instantly share code, notes, and snippets.

@Mk-Etlinger
Last active February 12, 2020 22:16
Show Gist options
  • Save Mk-Etlinger/84afc113c2c04fe51a629ea2314de709 to your computer and use it in GitHub Desktop.
Save Mk-Etlinger/84afc113c2c04fe51a629ea2314de709 to your computer and use it in GitHub Desktop.
Hacker Rank - pairSum v2
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