function findElement(arr, func) {
let num = 0;
for(let i = 0;i<=arr.length;i++){
//console.log(arr[i]);
//console.log(func(arr[i]));
console.log(`${arr[i]}:${func(arr[i])}`);
if(func(arr[i]) === true){
return arr[i];
}
else{
return undefined;
}
}
return num;
}
console.log(findElement([1, 2, 3, 4], num => num % 2 === 0));
Its not returning the true values but rather returning the false ones.