function twoSum(nums, target) {
const prevMap = new Map();
for (let i=0; i<nums.length; i++) {
let diff = target - nums[i];
if (prevMap.has(diff)) {
return [prevMap.get(diff), i];
}
prevMap.set(nums[i], i);
}
return [];
}
const nums = [1,2,3,4,5];
console.log(nums);
for (let i=1; i<10; i++) {
console.log(i, twoSum(nums, i));
}
To embed this project on your website, copy the following code and paste it into your website's HTML: