function twoSum(nums, target) {
const viewed = []; // access by index is faster that Map
for(let i=0; ;i++){ //according to task description - solution is always present - no need to check <.length or something like this
const current = nums[i];
const j = viewed[current];
if(j !== undefined){
return [i, j];
}
viewed[target - current] = i;
}
};
function sumDigit(nums, target) {
let mapping = {}
for(let i = 0; i < nums.length; i++) {
let n = nums[i]
if(mapping[target - n] != null) return [ mapping[target - n], i ]
mapping[n] = i
}
}
sumDigit([3,2,4], 6)
function twoSum(nums, target) {
const viewed = []; // access by index is faster that Map
for(let i=0; ;i++){ //according to task description - solution is always present - no need to check <.length or something like this
const current = nums[i];
const j = viewed[current];
if(j !== undefined){
return [i, j];
}
viewed[target - current] = i;
}
};