Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (27 sloc)
781 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |