I already figured out the challenge using a for loop, but I was trying to shorten my code and use ternary evaluations, this is what i have but its not working.
return arr.forEach(func) == true ? arr.indexOf(arr.forEach(func)) : undefined;
It’s not working correctly tho, any takers?
The original code without my solution:
function findElement(arr, func) {
let num = 0;
return num;
}
findElement([1, 2, 3, 4], num => num % 2 === 0);
**Link to the challenge:**
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers