Update baseEach modules.

This commit is contained in:
John-David Dalton
2017-03-10 22:57:22 -08:00
parent 4c77d8807c
commit fa8c607742
2 changed files with 37 additions and 4 deletions

View File

@@ -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

View File

@@ -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