Files
lodash/internal/createBaseEach.js
John-David Dalton fec213a98c Bump to v3.7.0.
2015-12-16 17:49:35 -08:00

31 lines
935 B
JavaScript

define(['./getLength', './isLength', './toObject'], function(getLength, isLength, toObject) {
/**
* Creates a `baseEach` or `baseEachRight` function.
*
* @private
* @param {Function} eachFunc The function to iterate over a collection.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new base function.
*/
function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) {
var length = collection ? getLength(collection) : 0;
if (!isLength(length)) {
return eachFunc(collection, iteratee);
}
var index = fromRight ? length : -1,
iterable = toObject(collection);
while ((fromRight ? index-- : ++index < length)) {
if (iteratee(iterable[index], index, iterable) === false) {
break;
}
}
return collection;
};
}
return createBaseEach;
});