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