You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							29 lines
						
					
					
						
							1.0 KiB
						
					
					
				
			
		
		
	
	
							29 lines
						
					
					
						
							1.0 KiB
						
					
					
				import isArrayLike from './_isArrayLike.js';
 | 
						|
import keys from './keys.js';
 | 
						|
import optimizeCb from './_optimizeCb.js';
 | 
						|
 | 
						|
// Internal helper to create a reducing function, iterating left or right.
 | 
						|
export default 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);
 | 
						|
  };
 | 
						|
}
 |