forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsome.js
29 lines (27 loc) · 781 Bytes
/
some.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Checks if `predicate` returns truthy for **any** element of `array`.
* Iteration is stopped once `predicate` returns truthy. The predicate is
* invoked with three arguments: (value, index, array).
*
* @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 any element passes the predicate check,
* else `false`.
* @example
*
* some([null, 0, 'yes', false], Boolean)
* // => true
*/
function some(array, predicate) {
let index = -1
const length = array == null ? 0 : array.length
while (++index < length) {
if (predicate(array[index], index, array)) {
return true
}
}
return false
}
export default some