Skip to content

Commit

Permalink
Create Sum_Of_Pairs.js
Browse files Browse the repository at this point in the history
  • Loading branch information
EgoriusTheGreat2 authored Oct 2, 2023
1 parent b06fb1b commit ced2126
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions codewars/Sum of pairs/Sum_Of_Pairs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function sumPairs(arr, target) {
let indices = new Map();

for (let i = 0; i < arr.length; i++) {
let complement = target - arr[i];

if (indices.has(complement)) {
return [complement, arr[i]];
}

indices.set(arr[i], i);
}

return undefined;
}

0 comments on commit ced2126

Please sign in to comment.