MCPcopy Create free account
hub / github.com/TruthHun/BookStack / createReduce

Function createReduce

static/word2md/mammoth.browser.js:28034–28057  ·  view source on GitHub ↗
(dir)

Source from the content-addressed store, hash-verified

28032
28033 // Create a reducing function iterating left or right.
28034 function createReduce(dir) {
28035 // Optimized iterator function as using arguments.length
28036 // in the main function will deoptimize the, see #1991.
28037 function iterator(obj, iteratee, memo, keys, index, length) {
28038 for (; index >= 0 && index < length; index += dir) {
28039 var currentKey = keys ? keys[index] : index;
28040 memo = iteratee(memo, obj[currentKey], currentKey, obj);
28041 }
28042 return memo;
28043 }
28044
28045 return function(obj, iteratee, memo, context) {
28046 iteratee = optimizeCb(iteratee, context, 4);
28047 var keys = !isArrayLike(obj) && _.keys(obj),
28048 length = (keys || obj).length,
28049 index = dir > 0 ? 0 : length - 1;
28050 // Determine the initial value if none is provided.
28051 if (arguments.length < 3) {
28052 memo = obj[keys ? keys[index] : index];
28053 index += dir;
28054 }
28055 return iterator(obj, iteratee, memo, keys, index, length);
28056 };
28057 }
28058
28059 // **Reduce** builds up a single result from a list of values, aka `inject`,
28060 // or `foldl`.

Callers 1

mammoth.browser.jsFile · 0.70

Calls 3

optimizeCbFunction · 0.70
isArrayLikeFunction · 0.70
iteratorFunction · 0.70

Tested by

no test coverage detected