diff --git a/.internal/arrayEvery.js b/.internal/arrayEvery.js deleted file mode 100644 index bc4595483..000000000 --- a/.internal/arrayEvery.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * A specialized version of `every` for arrays. - * - * @private - * @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`. - */ -function arrayEvery(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 arrayEvery diff --git a/.internal/baseEvery.js b/.internal/baseEvery.js deleted file mode 100644 index 3ff0cf1fb..000000000 --- a/.internal/baseEvery.js +++ /dev/null @@ -1,21 +0,0 @@ -import baseEach from './baseEach.js' - -/** - * The base implementation of `every`. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if all elements pass the predicate check, - * else `false` - */ -function baseEvery(collection, predicate) { - let result = true - baseEach(collection, (value, index, collection) => { - result = !!predicate(value, index, collection) - return result - }) - return result -} - -export default baseEvery diff --git a/every.js b/every.js index 3e3037d6a..79c329e32 100644 --- a/every.js +++ b/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 diff --git a/everyValue.js b/everyValue.js new file mode 100644 index 000000000..56e2d2614 --- /dev/null +++ b/everyValue.js @@ -0,0 +1,32 @@ +/** + * Checks if `predicate` returns truthy for **all** properties of `object`. + * Iteration is stopped once `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, key, object). + * + * **Note:** This method returns `true` for + * [empty objects](https://en.wikipedia.org/wiki/Empty_set) because + * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of + * elements of empty objects. + * + * @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 all properties pass the predicate check, + * else `false`. + * @example + * + * everyValue({ 'a': 0, 'b': 'yes', 'c': false }, Boolean) + * // => false + */ +function everyValue(object, predicate) { + const props = Object.keys(Object(object)) + for (const key of props) { + if (!predicate(object[key], key, object)) { + return false + } + } + return true +} + +export default everyValue