Array.prototype.every checks whether all elements of an array pass a test. It returns false the instant it finds one that fails, and true only if every element passes. It's the exact mirror of some: some looks for one success, every looks for one failure.
Implement arrayEvery(arr, callback, thisArg). Call callback on each element with (value, index, array); the moment one returns a falsy value, return false and stop. If none fails, return true. An empty array passes vacuously — with no element to break the rule, every returns true.
function arrayEvery(arr, callback, thisArg) {
// returns true if callback(value, index, arr) is truthy for EVERY element,
// false otherwise; stops at the first falsy result.
}
arrayEvery([2, 4, 6], (n) => n % 2 === 0); // true — all even
arrayEvery([2, 3, 4], (n) => n % 2 === 0); // false — 3 fails
arrayEvery([], () => false); // true — nothing to break the rule
true (vacuous truth). This surprises people; it's the opposite of some's empty-array false.0, '', null, undefined, NaN) counts as a failure, not just literal false.thisArg — when provided, sets this inside a regular callback.