Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / createBaseEach.js
1 var getLength = require('./getLength'),
2     isLength = require('./isLength'),
3     toObject = require('./toObject');
4
5 /**
6  * Creates a `baseEach` or `baseEachRight` function.
7  *
8  * @private
9  * @param {Function} eachFunc The function to iterate over a collection.
10  * @param {boolean} [fromRight] Specify iterating from right to left.
11  * @returns {Function} Returns the new base function.
12  */
13 function createBaseEach(eachFunc, fromRight) {
14   return function(collection, iteratee) {
15     var length = collection ? getLength(collection) : 0;
16     if (!isLength(length)) {
17       return eachFunc(collection, iteratee);
18     }
19     var index = fromRight ? length : -1,
20         iterable = toObject(collection);
21
22     while ((fromRight ? index-- : ++index < length)) {
23       if (iteratee(iterable[index], index, iterable) === false) {
24         break;
25       }
26     }
27     return collection;
28   };
29 }
30
31 module.exports = createBaseEach;