Closed kapreski closed 6 years ago
every
should return true for empty arrays (since there are no elements, every element does satisfy the predicate).
I'm not quite sure what you are asking about the loop exercise. Could you clarify?
I though the result should be false when we check against an empty array..
it's like saying:
is every element in [] == 5
the array is empty []
yet the answer is true
.
maybe I'll understand the logic later but since Array.prototype.every()
works the same way
I guess the question is beyond the book..
Big thank you for the book, really.
if the condition in the
test
function changed to something like==
the result is alwaystrue
if thearray
is empty. in thesome()
version the some function runs but we are flipping the result so it's always true ifarray
is empty. in thefor of
version the array is empty so it always short-circuit? I added a condition to check if the array is empty and return false if it is..function every(array, test){ return array.length > 0 && !array.some(el => !test(el)); }
what do you think? did I miss something?