Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

two sum js

var sumDigit = function(nums, target) {
    const indexArr = [];
    let i = 0
    
    while(true) {
      const current = nums[i];
      const j = indexArr[current];

      if(j !== undefined) return [i, j];
      indexArr[target - current] = i; 
      i++
    }
};

sumDigit([3,2,4], 6)
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #sum #js
ADD COMMENT
Topic
Name
6+2 =