So, I know how to solve this one with a for loop. And I read this post (freeCodeCamp Algorithm Challenge Guide: Finders Keepers) so now I know how to solve it using .filter().
I tend to reach for .map() a lot when I would have used a for loop before, but I couldn’t get this working using .map().
This is more or less what I was trying:
function findElement(arr, func) {
return arr.map(num => {
if(func){
return num
}
});
}
Can anyone explain where I went wrong? Thanks.