Solution 1 says to create an if statement without an else statement in the loop. Doesn’t the else statement of undefined go inside the loop with the if? I am thinking that an else statement inside would cover the case that no element satisfies the test function. A loop can- I found the answer but lost the rest of the question.
This is how I thought.
Why is else statement not inside loop? Computer will run the test searching for a truthy first. If there is a truthy, something follows. Outside that idea, the false array rests.
Why did and else statement fail to load with wrap written and pass as return statement only? At this point, there is not much of an else.
let num = 0;
for (let i = 0; i < arr.length; i++) {
num = arr[i];
if (func(num)) {
return num;
}
}
return undefined;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 Edg/87.0.664.75
.
Challenge: Finders Keepers
Link to the challenge: