How can we create a new array where all values are greater than the second value in the array provided? If the input array has less than two elements, the function should return false.
For example,
findValuesGreaterThanSecond([1,3,5,7])
would result in [5, 7].
findValuesGreaterThanSecond([0, -3, 2, 5])
would give us [0, 2, 5].
findValuesGreaterThanSecond([2])
should return false.
This is the approach I attempted:
function findValuesGreaterThanSecond(arr) {
for (let val of arr) {
if (val > arr[1]) {
return [val];
} else {
return false;
}
}
}