From 0706af154333f6fb74aaf1aa4ef62785e1333daa Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 14 Dec 2015 08:06:29 -0800 Subject: [PATCH] Ensure the fp `iteratee` wrapper enforces arity for functions with a `length` of `0`. --- lib/fp/base.js | 2 +- test/test-fp.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/fp/base.js b/lib/fp/base.js index 69f47979a..f43ee6240 100644 --- a/lib/fp/base.js +++ b/lib/fp/base.js @@ -102,7 +102,7 @@ function baseConvert(util, name, func) { arity = arity > 2 ? (arity - 2) : 1; func = iteratee(func); var length = func.length; - return length <= arity ? func : baseAry(func, arity); + return (length && length <= arity) ? func : baseAry(func, arity); }; }, 'mixin': function(mixin) { diff --git a/test/test-fp.js b/test/test-fp.js index e178d56cd..a8f4b9fb5 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -567,6 +567,28 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('reduce methods'); + + _.each(['reduce', 'reduceRight'], function(methodName) { + var func = fp[methodName], + array = [1, 2, 3], + isReduce = methodName == 'reduce'; + + QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) { + assert.expect(1); + + var args; + + func(function() { + args || (args = slice.call(arguments)); + })(0, array); + + assert.deepEqual(args, isReduce ? [0, 1] : [0, 3]); + }); + }); + + /*--------------------------------------------------------------------------*/ + QUnit.module('fp.runInContext'); (function() {