Function: Finders Keepers

Why must I include (num) in if (func(num) === true)?

Your code so far

function findElement(arr, func) {
  for(var i = 0; i < arr.length; i++){
    var num = arr[i];
    if(func(num) === true){
      return num;
  } 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_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36.

Link to the challenge:

Func is a parameter that holds a reference to a function. You need to call it and pass an argument into it, in order to get a boolean result that you can compare to true.

Learn more about callbacks and higher order functions in javascript to understand this better.

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Also, if it one of the solutions of the guild, please, post the link to the guild and indicate which solution you are talking about instead of posting the full working solution.

We are trying to cut down the number of full working solutions found in the forum.

Thank you.