Files
lodash/.internal/baseEach.js
2017-03-11 21:41:07 -08:00

32 lines
762 B
JavaScript

import baseForOwn from './baseForOwn.js'
import isArrayLike from '../isArrayLike.js'
/**
* The base implementation of `forEach`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object} Returns `collection`.
*/
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