Given an array of integers nums and an integer target, create a function that returns the two numbers such that they add up to target
Initialise a recursive function, and return a result based on the following conditions:
- Return result as null if n is equivalent to the length of array
- Return result as an array of numbers, containing two values that sum up to target
- Call findTarget with n incremented by 1.
`
function findTarget(array, n, target) {
let result = null;
if (n === array.length) return (result = null), result;
return (
(result = array.filter(
(int, index) => index !== n && array[n] + int === target
)),
result.length ? [array[n], ...result] : findTarget(array, (n += 1), target)
);
}
`