(dir)
| 1381 | |
| 1382 | // Internal helper to create a reducing function, iterating left or right. |
| 1383 | function createReduce(dir) { |
| 1384 | // Wrap code that reassigns argument variables in a separate function than |
| 1385 | // the one that accesses `arguments.length` to avoid a perf hit. (#1991) |
| 1386 | var reducer = function(obj, iteratee, memo, initial) { |
| 1387 | var _keys = !isArrayLike(obj) && keys(obj), |
| 1388 | length = (_keys || obj).length, |
| 1389 | index = dir > 0 ? 0 : length - 1; |
| 1390 | if (!initial) { |
| 1391 | memo = obj[_keys ? _keys[index] : index]; |
| 1392 | index += dir; |
| 1393 | } |
| 1394 | for (; index >= 0 && index < length; index += dir) { |
| 1395 | var currentKey = _keys ? _keys[index] : index; |
| 1396 | memo = iteratee(memo, obj[currentKey], currentKey, obj); |
| 1397 | } |
| 1398 | return memo; |
| 1399 | }; |
| 1400 | |
| 1401 | return function(obj, iteratee, memo, context) { |
| 1402 | var initial = arguments.length >= 3; |
| 1403 | return reducer(obj, optimizeCb(iteratee, context, 4), memo, initial); |
| 1404 | }; |
| 1405 | } |
| 1406 | |
| 1407 | // **Reduce** builds up a single result from a list of values, aka `inject`, |
| 1408 | // or `foldl`. |
no test coverage detected
searching dependent graphs…