i am making one function that is finding the index of two values that sums up to 9
var twoSum = function(nums, target) {
let obj ={};
const result = [];
for(let i =0; i< nums.length; i++){
if(obj[nums[i]]){
result.push(obj[nums[i]]);
result.push(i);
}
let a = target - nums[i];
obj[a] = i;
console.log(obj)
}
console.log(result)
};
twoSum([2 ,4 ,7 ,8 ], 9);
//OUTPUT
{ 7: 0 }
{ 5: 1 , 7: 0 }
{ 2: 2 , 5: 1 , 7: 0 }
{ 1: 3 , 2: 2 , 5: 1 , 7: 0 }
here the items are apended to object in some random sort of way. instead they should apeended one after the another why?