mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
wip: migrate to bun
This commit is contained in:
34
src/every.ts
Normal file
34
src/every.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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;
|
||||
Reference in New Issue
Block a user