My code:
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);
With the above code, the following criteria for the exercise is not met: “findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; })` should return undefined”
However when i run the function with that array and log the results to the console it does in fact return undefined.
Bug in the exercise??
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers