Tell us what’s happening:
I have completed this using for loop but can someone please help me understand whether or not I can do this using forEach and if so then how? I did attempt it and have commented the same!
Thanks for the help!
Cheers!
Your code so far
function findElement(arr, func) {
// arr.forEach(function(item){
// if(func(item)){
// return item;
// }
// });
for(let i = 0; i < arr.length; i++){
if(func(arr[i])){
return arr[i];
}
}
}
// findElement([1, 2, 3, 4], num => num % 2 === 0);
findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; })
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0.
Challenge: Finders Keepers
Link to the challenge:
