Array.prototype.someLoading saved progress…

Array.prototype.some

Array.prototype.some answers a yes/no question about an array: does at least one element pass this test? It returns true the instant it finds a match and stops looking; if it reaches the end without one, it returns false.

Implement arraySome(arr, callback, thisArg). Call callback on each element with (value, index, array); the moment one returns a truthy value, return true and stop. If none does, return false. An empty array has nothing to satisfy the test, so it returns false.

Signature

function arraySome(arr, callback, thisArg) {
  // returns true if callback(value, index, arr) is truthy for ANY element,
  // false otherwise; stops at the first truthy result.
}

Examples

arraySome([1, 2, 3], (n) => n % 2 === 0); // true  — 2 passes
arraySome([1, 3, 5], (n) => n % 2 === 0); // false — none pass
arraySome([], () => true); // false — nothing to test

Notes

  • Short-circuit — stop as soon as the callback returns truthy. Don't keep scanning the rest of the array.
  • Empty array — returns false. There is no element to satisfy the predicate.
  • Truthiness — any truthy return counts as a pass (1, 'x', []), not just literal true.
  • Sparse holes — skip holes in a sparse array; don't test them.
  • thisArg — when provided, sets this inside a regular callback.
Loading editor…