Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getSumIndices = (arr, target) => {
- if (target === undefined || arr.length < 2) return 0;
- const differences = {};
- const result = [];
- for (let i = 0; i < arr.length; i++) {
- const current = arr[i];
- if (differences[current] !== undefined) {
- result.push([differences[current], i]);
- delete differences[current];
- } else {
- const diff = target - current;
- if (!differences[current] && !differences[diff]) differences[diff] = i;
- }
- }
- return result;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement