Tell us what’s happening:
Can’t figure out why this condition if (func.call(null, arr[i]))
is not being evaluated to true
or false
inside the statement, even though when I console.log it I’m getting true
of false
on each array element…
Your code so far
function findElement(arr, func) {
let num = 0;
for (let i=0; i<arr.length; i++) {
if (func.call(null, arr[i])) {
return arr[i];
} else {
return undefined;
}
}
}
findElement([1, 2, 3, 4], num => num % 2 === 0);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
.
Link to the challenge: