Use the every Method to Check that Every Element in an Array Meets a Criteria - bringing up an old question

I had all the same questions as this post >>> link.

But one question that remains unanswered, as far as I can tell, is why we need 2 return statements for the true testcase but not the false ones? The false testcases passed before I added the 2nd return statement (return arr.every) but the true testcase only passed after I added it in.

My bottom line question: shouldn’t all test-cases have failed before adding in the 2nd return statement?

Thank you.

Maybe you’re getting confused with the ES6 arrow function syntax?

const myArr = [1, 2, 3, 4, 5];
return myArr.every(function(currentValue) {
    return currentValue > 0;
});

Is equivalent to…

const myArr = [1, 2, 3, 4, 5];
return myArr.every((currentValue) => currentValue > 0);
1 Like