That makes sense. The way I was thinking of it was that num would only be returned if func evaluated to true, so it would work the same way that using .filter() would, and you would return newArr[0].
There are ways to use map() in this challenge, but not without writing more code than necessary. This is a job for filter().
Take a look at the following minimalist solution. If it makes little sense, try to rewrite it more verbosely. It uses arrow syntax, which allows you to omit curly brackets and the words function and return .
let findElement = (arr, func) => arr.filter(func)[0];
Thank you all for your responses. I will try and honor the moderator’s request to not simply post a solution.
I found the simplest code solution to be with the find() method. You can literally write one line inside the function.
I hope this helps. https://www.w3schools.com/jsref/jsref_find.asp
First, I solved this challenge without using the func (function)… then I went back and after seeing your post I considered I could try to solve this using the Map() function as you suggested… which I solved ,
however, it still involved a For loop due to the fact that the Map() function creates an array instead of a string Sooooo… it looked more like
let myArr=arr.map(func);
for(let x=0;x<myArr.length;x++)
in order to sort through the array to find the truth value… It is however in the end cleaner apparently to use the filter method suggested after your post. But I thought I would leave this here just in case you still wanted to use map() instead…