mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Ensure fp pickBy and omitBy provide value and key arguments.
This commit is contained in:
@@ -152,15 +152,15 @@ function baseConvert(util, name, func, options) {
|
|||||||
'iteratee': function(iteratee) {
|
'iteratee': function(iteratee) {
|
||||||
return function() {
|
return function() {
|
||||||
var func = arguments[0],
|
var func = arguments[0],
|
||||||
arity = arguments[1];
|
arity = arguments[1],
|
||||||
|
result = iteratee(func, arity),
|
||||||
|
length = result.length;
|
||||||
|
|
||||||
if (!config.cap) {
|
if (config.cap && typeof arity == 'number') {
|
||||||
return iteratee(func, arity);
|
arity = arity > 2 ? (arity - 2) : 1;
|
||||||
|
return (length && length <= arity) ? result : baseAry(result, arity);
|
||||||
}
|
}
|
||||||
arity = arity > 2 ? (arity - 2) : 1;
|
return result;
|
||||||
func = iteratee(func);
|
|
||||||
var length = func.length;
|
|
||||||
return (length && length <= arity) ? func : baseAry(func, arity);
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
'mixin': function(mixin) {
|
'mixin': function(mixin) {
|
||||||
|
|||||||
@@ -11684,7 +11684,7 @@
|
|||||||
* // => { 'b': '2' }
|
* // => { 'b': '2' }
|
||||||
*/
|
*/
|
||||||
function omitBy(object, predicate) {
|
function omitBy(object, predicate) {
|
||||||
predicate = getIteratee(predicate, 2);
|
predicate = getIteratee(predicate);
|
||||||
return basePickBy(object, function(value, key) {
|
return basePickBy(object, function(value, key) {
|
||||||
return !predicate(value, key);
|
return !predicate(value, key);
|
||||||
});
|
});
|
||||||
@@ -11729,7 +11729,7 @@
|
|||||||
* // => { 'a': 1, 'c': 3 }
|
* // => { 'a': 1, 'c': 3 }
|
||||||
*/
|
*/
|
||||||
function pickBy(object, predicate) {
|
function pickBy(object, predicate) {
|
||||||
return object == null ? {} : basePickBy(object, getIteratee(predicate, 2));
|
return object == null ? {} : basePickBy(object, getIteratee(predicate));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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');
|
QUnit.module('fp.partial and fp.partialRight');
|
||||||
|
|
||||||
_.each(['partial', 'partialRight'], function(methodName) {
|
_.each(['partial', 'partialRight'], function(methodName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user