mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Split out every into everyValue.
This commit is contained in:
30
every.js
30
every.js
@@ -1,19 +1,16 @@
|
||||
import arrayEvery from './.internal/arrayEvery.js'
|
||||
import baseEvery from './.internal/baseEvery.js'
|
||||
|
||||
/**
|
||||
* Checks if `predicate` returns truthy for **all** elements of `collection`.
|
||||
* 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|key, collection).
|
||||
* invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* **Note:** This method returns `true` for
|
||||
* [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
|
||||
* [empty arrays](https://en.wikipedia.org/wiki/Empty_set) because
|
||||
* [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
|
||||
* elements of empty collections.
|
||||
* elements of empty arrays.
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @category Collection
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @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`.
|
||||
@@ -22,9 +19,16 @@ import baseEvery from './.internal/baseEvery.js'
|
||||
* every([true, 1, null, 'yes'], Boolean)
|
||||
* // => false
|
||||
*/
|
||||
function every(collection, predicate) {
|
||||
const func = Array.isArray(collection) ? arrayEvery : baseEvery
|
||||
return func(collection, predicate)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user