diff --git a/.internal/arrayIncludesWith.js b/.internal/arrayIncludesWith.js index 64c54134a..09e35dfe3 100644 --- a/.internal/arrayIncludesWith.js +++ b/.internal/arrayIncludesWith.js @@ -7,12 +7,13 @@ * @param {Function} comparator The comparator invoked per element. * @returns {boolean} Returns `true` if `target` is found, else `false`. */ -function arrayIncludesWith(array, value, comparator) { - let index = -1 - const length = array == null ? 0 : array.length +function arrayIncludesWith(array, target, comparator) { + if (array == null) { + return false + } - while (++index < length) { - if (comparator(value, array[index])) { + for (const value of array) { + if (comparator(target, value)) { return true } } diff --git a/.internal/baseFlatten.js b/.internal/baseFlatten.js index 353efcc9c..dc1d9df98 100644 --- a/.internal/baseFlatten.js +++ b/.internal/baseFlatten.js @@ -12,14 +12,14 @@ import isFlattenable from './isFlattenable.js' * @returns {Array} Returns the new flattened array. */ function baseFlatten(array, depth, predicate, isStrict, result) { - let index = -1 - const { length } = array - predicate || (predicate = isFlattenable) result || (result = []) - while (++index < length) { - const value = array[index] + if (array == null) { + return result + } + + for (const value of array) { if (depth > 0 && predicate(value)) { if (depth > 1) { // Recursively flatten arrays (susceptible to call stack limits). diff --git a/compact.js b/compact.js index a6731029a..5078673e8 100644 --- a/compact.js +++ b/compact.js @@ -12,13 +12,14 @@ * // => [1, 2, 3] */ function compact(array) { - let index = -1 let resIndex = 0 - const length = array == null ? 0 : array.length const result = [] - while (++index < length) { - const value = array[index] + if (array == null) { + return result + } + + for (const value of array) { if (value) { result[resIndex++] = value }