{"size": 1075, "ext": "js", "max_stars_repo_path": "node_modules/underscore/cjs/_createReduce.js", "max_stars_repo_name": "miguelbuca/canopus-api", "max_stars_repo_stars_event_min_datetime": "2015-01-29T17:11:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T21:12:00.000Z", "max_issues_repo_path": "node_modules/underscore/cjs/_createReduce.js", "max_issues_repo_name": "miguelbuca/canopus-api", "max_issues_repo_issues_event_min_datetime": "2015-01-30T05:33:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:17:21.000Z", "max_forks_repo_path": "node_modules/underscore/cjs/_createReduce.js", "max_forks_repo_name": "miguelbuca/canopus-api", "max_forks_repo_forks_event_min_datetime": "2015-01-29T16:26:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T07:44:30.000Z"}
{"max_stars_count": 12278, "max_issues_count": 9469, "max_forks_count": 892, "avg_line_length": 34.6774193548, "max_line_length": 76, "alphanum_fraction": 0.6418604651}
var _isArrayLike = require('./_isArrayLike.js');
var keys = require('./keys.js');
var _optimizeCb = require('./_optimizeCb.js');

// Internal helper to create a reducing function, iterating left or right.
function createReduce(dir) {
  // Wrap code that reassigns argument variables in a separate function than
  // the one that accesses `arguments.length` to avoid a perf hit. (#1991)
  var reducer = function(obj, iteratee, memo, initial) {
    var _keys = !_isArrayLike(obj) && keys(obj),
        length = (_keys || obj).length,
        index = dir > 0 ? 0 : length - 1;
    if (!initial) {
      memo = obj[_keys ? _keys[index] : index];
      index += dir;
    }
    for (; index >= 0 && index < length; index += dir) {
      var currentKey = _keys ? _keys[index] : index;
      memo = iteratee(memo, obj[currentKey], currentKey, obj);
    }
    return memo;
  };

  return function(obj, iteratee, memo, context) {
    var initial = arguments.length >= 3;
    return reducer(obj, _optimizeCb(iteratee, context, 4), memo, initial);
  };
}

module.exports = createReduce;
