The Wayback Machine - https://web.archive.org/web/20170626174140/https://github.com/lodash/lodash/blob/master/every.js
Skip to content
Permalink
73ce606 Apr 16, 2017
35 lines (32 sloc) 1000 Bytes
/**
* Checks if `predicate` returns truthy for **all** elements of `array`.
* Iteration is stopped once `predicate` returns falsey. The predicate is
* invoked with three arguments: (value, index, array).
*
* **Note:** This method returns `true` for
* [empty arrays](https://en.wikipedia.org/wiki/Empty_set) because
* [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
* elements of empty arrays.
*
* @since 5.0.0
* @category Array
* @param {Array} array The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if all elements pass the predicate check,
* else `false`.
* @example
*
* every([true, 1, null, 'yes'], Boolean)
* // => false
*/
function every(array, predicate) {
let index = -1
const length = array == null ? 0 : array.length
while (++index < length) {
if (!predicate(array[index], index, array)) {
return false
}
}
return true
}
export default every
You can't perform that action at this time.
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.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.