1 2 3 4 5 6 7 8 9 10 11 12 13 14
| const findSumBetter = (arr, weight) => { let hashtable = {}; for (let i = 0, arrLength = arr.length; i < arrLength; i++) { let currentElement = arr[i]; let difference = weight - currentElement;
if (hashtable[currentElement] != undefined) { return [i, hashTable[currentElement]]; } else { hashtable[difference] = i; } } return -1; };
|