Basic Algorithm Scripting - Finders Keepers

I have the solution here, but I don’t understand the if statement used because It does not seem complete to me. It does not seem to give a requirement of (func(num)), it just says always return num. I’m confused again…

function findElement(arr, func) {
  let num = 0;

  for (let i = 0; i < arr.length; i++) {
    num = arr[i];
    if (func(num)) {
      return num;

  return undefined;

findElement([1, 2, 3, 4], num => num % 2 === 0);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic Algorithm Scripting - Finders Keepers

Link to the challenge:

Depending what is actually returned by func(num), the result, will be evaluated as truthy or falsy. Condition in the if statement doesn’t need to be exactly true or false.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.