From fa8c607742ea670bb60477db9feb79f732595e69 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 10 Mar 2017 22:57:22 -0800 Subject: [PATCH] Update `baseEach` modules. --- .internal/baseEach.js | 21 +++++++++++++++++++-- .internal/baseEachRight.js | 20 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/.internal/baseEach.js b/.internal/baseEach.js index 88159f4b0..e251680d8 100644 --- a/.internal/baseEach.js +++ b/.internal/baseEach.js @@ -1,5 +1,5 @@ import baseForOwn from './baseForOwn.js' -import createBaseEach from './createBaseEach.js' +import isArrayLike from '../isArrayLike.js' /** * The base implementation of `forEach`. @@ -9,6 +9,23 @@ import createBaseEach from './createBaseEach.js' * @param {Function} iteratee The function invoked per iteration. * @returns {Array|Object} Returns `collection`. */ -const baseEach = createBaseEach(baseForOwn) +function baseEach(collection, iteratee) { + if (collection == null) { + return collection + } + if (!isArrayLike(collection)) { + return baseForOwn(collection, iteratee) + } + var length = collection.length, + index = -1, + iterable = Object(collection) + + while (++index < length) { + if (iteratee(iterable[index], index, iterable) === false) { + break + } + } + return collection +} export default baseEach diff --git a/.internal/baseEachRight.js b/.internal/baseEachRight.js index a034067a1..de6d4ff19 100644 --- a/.internal/baseEachRight.js +++ b/.internal/baseEachRight.js @@ -1,5 +1,5 @@ import baseForOwnRight from './baseForOwnRight.js' -import createBaseEach from './createBaseEach.js' +import isArrayLike from '../isArrayLike.js' /** * The base implementation of `forEachRight`. @@ -9,6 +9,22 @@ import createBaseEach from './createBaseEach.js' * @param {Function} iteratee The function invoked per iteration. * @returns {Array|Object} Returns `collection`. */ -const baseEachRight = createBaseEach(baseForOwnRight, true) +function baseEachRight(collection, iteratee) { + if (collection == null) { + return collection + } + if (!isArrayLike(collection)) { + return baseForOwnRight(collection, iteratee) + } + var length = collection.length, + iterable = Object(collection) + + while (length--) { + if (iteratee(iterable[length], length, iterable) === false) { + break + } + } + return collection +} export default baseEachRight