You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.
Analogous to the some method, arrays also have an every method. This one returns true when the given function returns true for every element in the array. In a way, some is a version of the || operator that acts on arrays, and every is like the && operator.
Implement every as a function that takes an array and a predicate function as parameters. Write two versions, one using a loop and one using the some method.
*/
// Version 1 of every() written using Loops
function every(array, test) {
for (let element of array) {
if (!test(element)) {
return false;
}
}
return true;
}
// Version 2 of every() written using arr.some() method
function every2(array, test) {
// To build every on top of some, we can apply De Morgan’s laws,
// which state that a && b equals !(!a || !b).
//
// This can be generalized to arrays, where all elements in
// the array match if there is no element in the array that