diff --git a/.internal/arraySome.js b/.internal/arraySome.js deleted file mode 100644 index 33c239de2..000000000 --- a/.internal/arraySome.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * A specialized version of `some` for arrays. - * - * @private - * @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`. - */ -function arraySome(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 arraySome diff --git a/.internal/baseSome.js b/.internal/baseSome.js deleted file mode 100644 index 88b5ee538..000000000 --- a/.internal/baseSome.js +++ /dev/null @@ -1,22 +0,0 @@ -import baseEach from './baseEach.js' - -/** - * The base implementation of `some`. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if any element passes the predicate check, - * else `false`. - */ -function baseSome(collection, predicate) { - let result - - baseEach(collection, (value, index, collection) => { - result = predicate(value, index, collection) - return !result - }) - return !!result -} - -export default baseSome diff --git a/some.js b/some.js index b57ef96bd..25201f023 100644 --- a/some.js +++ b/some.js @@ -1,14 +1,11 @@ -import arraySome from './.internal/arraySome.js' -import baseSome from './.internal/baseSome.js' - /** - * Checks if `predicate` returns truthy for **any** element of `collection`. + * 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|key, collection). + * invoked with three arguments: (value, index, array). * - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. + * @since 5.0.0 + * @category array + * @param {Array|Object} 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`. @@ -17,9 +14,16 @@ import baseSome from './.internal/baseSome.js' * some([null, 0, 'yes', false], Boolean) * // => true */ -function some(collection, predicate) { - const func = Array.isArray(collection) ? arraySome : baseSome - return func(collection, predicate) +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 diff --git a/someObj.js b/someObj.js new file mode 100644 index 000000000..f69c4d9c3 --- /dev/null +++ b/someObj.js @@ -0,0 +1,27 @@ +/** + * Checks if `predicate` returns truthy for **any** element of `object`. + * Iteration is stopped once `predicate` returns truthy. The predicate is + * invoked with three arguments: (value, key, object). + * + * @since 5.0.0 + * @category Object + * @param {Object} object The object 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 someObj(object, predicate) { + let result + + Object.keys(object).forEach((key) => { + result = predicate(object[key], key, object) + return !result + }) + return !!result +} + +export default someObj