MCPcopy Create free account
hub / github.com/dtmilano/AndroidViewClient / createReduce

Function createReduce

docs/_static/underscore-1.13.1.js:1355–1377  ·  view source on GitHub ↗
(dir)

Source from the content-addressed store, hash-verified

1353
1354 // Internal helper to create a reducing function, iterating left or right.
1355 function createReduce(dir) {
1356 // Wrap code that reassigns argument variables in a separate function than
1357 // the one that accesses `arguments.length` to avoid a perf hit. (#1991)
1358 var reducer = function(obj, iteratee, memo, initial) {
1359 var _keys = !isArrayLike(obj) && keys(obj),
1360 length = (_keys || obj).length,
1361 index = dir > 0 ? 0 : length - 1;
1362 if (!initial) {
1363 memo = obj[_keys ? _keys[index] : index];
1364 index += dir;
1365 }
1366 for (; index >= 0 && index < length; index += dir) {
1367 var currentKey = _keys ? _keys[index] : index;
1368 memo = iteratee(memo, obj[currentKey], currentKey, obj);
1369 }
1370 return memo;
1371 };
1372
1373 return function(obj, iteratee, memo, context) {
1374 var initial = arguments.length >= 3;
1375 return reducer(obj, optimizeCb(iteratee, context, 4), memo, initial);
1376 };
1377 }
1378
1379 // **Reduce** builds up a single result from a list of values, aka `inject`,
1380 // or `foldl`.

Callers 1

Calls 2

reducerFunction · 0.85
optimizeCbFunction · 0.85

Tested by

no test coverage detected