any improvements for my javascript solution


  • 0
    R

    any suggestions for improvements

    var twoSum = function(nums, target) {
        return nums.reduce((acc, num, index) => {
            if (nums.indexOf(Math.abs(num - target)) != -1 && acc.length < 2) {
                acc.push(index)
            }
            return acc
        }, [])
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.