Last change
on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
886 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var isArrayLike = require('./isArrayLike');
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * Creates a `baseEach` or `baseEachRight` function.
|
---|
| 5 | *
|
---|
| 6 | * @private
|
---|
| 7 | * @param {Function} eachFunc The function to iterate over a collection.
|
---|
| 8 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
---|
| 9 | * @returns {Function} Returns the new base function.
|
---|
| 10 | */
|
---|
| 11 | function createBaseEach(eachFunc, fromRight) {
|
---|
| 12 | return function(collection, iteratee) {
|
---|
| 13 | if (collection == null) {
|
---|
| 14 | return collection;
|
---|
| 15 | }
|
---|
| 16 | if (!isArrayLike(collection)) {
|
---|
| 17 | return eachFunc(collection, iteratee);
|
---|
| 18 | }
|
---|
| 19 | var length = collection.length,
|
---|
| 20 | index = fromRight ? length : -1,
|
---|
| 21 | iterable = Object(collection);
|
---|
| 22 |
|
---|
| 23 | while ((fromRight ? index-- : ++index < length)) {
|
---|
| 24 | if (iteratee(iterable[index], index, iterable) === false) {
|
---|
| 25 | break;
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 | return collection;
|
---|
| 29 | };
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | module.exports = createBaseEach;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.