SOURCE

function towSum(nums, target) {
    for(let i=0,len=nums.length;i < len; i++) {
        for (let j = 0; j < len; j++) {
            if (i !== j && (nums[i] + nums[j]) === target) {
                return [i, j]
            }
        }
    }
}

const nums = [2, 7, 11, 15, 12, 90], target=92;
console.log(towSum(nums, target))

function towSum2(nums, target) {
    const map = {};
    for(let i = 0,len = nums.length; i < len; i++) {
        const n = nums[i];
        if ((target - n) in map) {
            return [map[target - n], i]
        } else {
            map[n] = i
        }
    }
}

console.log(towSum2(nums, target))
console 命令行工具 X clear

                    
>
console