0
1
YYusifHasanov
The const twoSum variable is initialized with an empty array and then each of the nums variable's length is used to initialize an individual array within the twoSum array. A for loop iterates through each of the nums variable's length and checks to see if the nums[i] + nums[j] value equals the target value. If it does, the value at position [i,j] within the result array is set to the value at position [i,j] within the nums array. Finally, the for loop breaks out of the loop.
const twoSum = (nums, target) => {
let result = [];
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) {
result=[i,j]
break;
}
}
}
return result
}