# Basic Algorithm Scripting - Finders Keepers

Can anyone help with the explanation of this problem in layman’s terms please?

``````function findElement(arr, func) {

}

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

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

Challenge: Basic Algorithm Scripting - Finders Keepers

“Layman’s terms” would be explaining it to people that don’t code.

The instructions are:

Create a function that looks through an array `arr` and returns the first element in it that passes a ‘truth test’. This means that given an element `x` , the ‘truth test’ is passed if `func(x)` is `true` . If no element passes the test, return `undefined` .

This is the starter code:

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

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

In that example giving, the function is checking if the modulus of 2 is 0 - in other words if it is evenly divisible by 2 - in other words if it is even. We need to return the first element that passes that test. The second element, `2`, is the first one that passes that test, so that is what I would expect it to return.

If you need more explanation than that, please ask a specific question. Specific questions get you better answers.

The challenge tests if you can find any number in the array that is divisible by 2. First step is to loop over the array, find any first number that is divisible by 2 and return it. if no number is available, then the function should return undefined automatically. Below is my solution:

mod edit: solution redacted

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.