Make _.omitBy and _.pickBy pass a key param to iteratees.

This commit is contained in:
John-David Dalton
2016-01-15 01:15:31 -08:00
parent f31fb8bd34
commit 1df18a3e10
2 changed files with 11 additions and 8 deletions

View File

@@ -3104,7 +3104,7 @@
function basePickBy(object, predicate) {
var result = {};
baseForIn(object, function(value, key) {
if (predicate(value)) {
if (predicate(value, key)) {
result[key] = value;
}
});
@@ -11250,9 +11250,9 @@
* // => { 'b': '2' }
*/
function omitBy(object, predicate) {
predicate = getIteratee(predicate);
return basePickBy(object, function(value) {
return !predicate(value);
predicate = getIteratee(predicate, 2);
return basePickBy(object, function(value, key) {
return !predicate(value, key);
});
}
@@ -11295,7 +11295,7 @@
* // => { 'a': 1, 'c': 3 }
*/
function pickBy(object, predicate) {
return object == null ? {} : basePickBy(object, getIteratee(predicate));
return object == null ? {} : basePickBy(object, getIteratee(predicate, 2));
}
/**

View File

@@ -5785,6 +5785,7 @@
func = _[methodName],
isBy = /(^partition|By)$/.test(methodName),
isFind = /^find/.test(methodName),
isOmitPick = /^(?:omit|pick)By$/.test(methodName),
isSome = methodName == 'some';
QUnit.test('`_.' + methodName + '` should provide the correct iteratee arguments', function(assert) {
@@ -5806,7 +5807,7 @@
expected[1] += '';
}
if (isBy) {
expected.length = 1;
expected.length = isOmitPick ? 2 : 1;
}
assert.deepEqual(args, expected);
}
@@ -5822,11 +5823,13 @@
var array = [1];
array[2] = 3;
var expected = [[1, 0, array], [undefined, 1, array], [3, 2, array]];
var expected = lodashStable.includes(objectMethods, methodName)
? [[1, '0', array], [undefined, '1', array], [3, '2', array]]
: [[1, 0, array], [undefined, 1, array], [3, 2, array]];
if (isBy) {
expected = lodashStable.map(expected, function(args) {
return args.slice(0, 1);
return args.slice(0, isOmitPick ? 2 : 1);
});
}
else if (lodashStable.includes(objectMethods, methodName)) {