My task is to write a function that takes an array of numbers and a target number
I must find two numbers in the array that add together to form the target, and then return the indices of the two numbers as a tuplet, like so (index1, index2).
I have created a nested for loop to compare each element of the array to each other element, and then ran an if statement to return the indices when the target value has been reached.
However, something is not working. I am not sure how to return as a tuplet or perhaps my code to get the indices is wrong. Any help or hints would be very appreciated. Thank you
function twoSum(numbers, target) {
for (let i = 0; i < numbers.length; i++) {
for (let j = 0; j < numbers.length; j++) {
if (numbers[i] + numbers[j] === target) {
return [numbers.indexOf(i), numbers.indexOf(j)];
}
}
}
}