DEV Community

Discussion on: Array manipulation in JavaScript 🧐

Collapse
 
cedpoilly profile image
Cedric

Cool man,thanks. What about some() though?
developer.mozilla.org/en-US/docs/W...

Collapse
 
qm3ster profile image
Mihail Malo • Edited

It tries the predicate on every item until it returns a truthy value.
If it reaches the end, returns false instead:

Array.prototype.some = function some(fn){
  for (const item of this) if (fn(item)) return true
  return false
}

The opposite is every():

Array.prototype.every = function every(fn){
  for (const item of this) if (!fn(item)) return false
  return true
}