Ensure fp pickBy and omitBy provide value and key arguments.

This commit is contained in:
John-David Dalton
2016-02-18 01:08:19 -08:00
parent 23768398c5
commit 48dbf203a5
3 changed files with 30 additions and 9 deletions

View File

@@ -152,15 +152,15 @@ function baseConvert(util, name, func, options) {
'iteratee': function(iteratee) {
return function() {
var func = arguments[0],
arity = arguments[1];
arity = arguments[1],
result = iteratee(func, arity),
length = result.length;
if (!config.cap) {
return iteratee(func, arity);
if (config.cap && typeof arity == 'number') {
arity = arity > 2 ? (arity - 2) : 1;
return (length && length <= arity) ? result : baseAry(result, arity);
}
arity = arity > 2 ? (arity - 2) : 1;
func = iteratee(func);
var length = func.length;
return (length && length <= arity) ? func : baseAry(func, arity);
return result;
};
},
'mixin': function(mixin) {

View File

@@ -11684,7 +11684,7 @@
* // => { 'b': '2' }
*/
function omitBy(object, predicate) {
predicate = getIteratee(predicate, 2);
predicate = getIteratee(predicate);
return basePickBy(object, function(value, key) {
return !predicate(value, key);
});
@@ -11729,7 +11729,7 @@
* // => { 'a': 1, 'c': 3 }
*/
function pickBy(object, predicate) {
return object == null ? {} : basePickBy(object, getIteratee(predicate, 2));
return object == null ? {} : basePickBy(object, getIteratee(predicate));
}
/**

View File

@@ -1173,6 +1173,27 @@
/*--------------------------------------------------------------------------*/
QUnit.module('fp.omitBy and fp.pickBy');
_.each(['omitBy', 'pickBy'], function(methodName) {
var func = fp[methodName];
QUnit.test('`fp.' + methodName + '` should provide `value` and `key` to `iteratee`', function(assert) {
assert.expect(1);
var args,
object = { 'a': 1 };
func(function() {
args || (args = slice.call(arguments));
})(object);
assert.deepEqual(args, [1, 'a']);
});
});
/*--------------------------------------------------------------------------*/
QUnit.module('fp.partial and fp.partialRight');
_.each(['partial', 'partialRight'], function(methodName) {