mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Update baseEach modules.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import baseForOwn from './baseForOwn.js'
|
import baseForOwn from './baseForOwn.js'
|
||||||
import createBaseEach from './createBaseEach.js'
|
import isArrayLike from '../isArrayLike.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `forEach`.
|
* The base implementation of `forEach`.
|
||||||
@@ -9,6 +9,23 @@ import createBaseEach from './createBaseEach.js'
|
|||||||
* @param {Function} iteratee The function invoked per iteration.
|
* @param {Function} iteratee The function invoked per iteration.
|
||||||
* @returns {Array|Object} Returns `collection`.
|
* @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
|
export default baseEach
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import baseForOwnRight from './baseForOwnRight.js'
|
import baseForOwnRight from './baseForOwnRight.js'
|
||||||
import createBaseEach from './createBaseEach.js'
|
import isArrayLike from '../isArrayLike.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `forEachRight`.
|
* The base implementation of `forEachRight`.
|
||||||
@@ -9,6 +9,22 @@ import createBaseEach from './createBaseEach.js'
|
|||||||
* @param {Function} iteratee The function invoked per iteration.
|
* @param {Function} iteratee The function invoked per iteration.
|
||||||
* @returns {Array|Object} Returns `collection`.
|
* @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
|
export default baseEachRight
|
||||||
|
|||||||
Reference in New Issue
Block a user