mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Make _.omitBy and _.pickBy pass a key param to iteratees.
This commit is contained in:
10
lodash.js
10
lodash.js
@@ -3104,7 +3104,7 @@
|
|||||||
function basePickBy(object, predicate) {
|
function basePickBy(object, predicate) {
|
||||||
var result = {};
|
var result = {};
|
||||||
baseForIn(object, function(value, key) {
|
baseForIn(object, function(value, key) {
|
||||||
if (predicate(value)) {
|
if (predicate(value, key)) {
|
||||||
result[key] = value;
|
result[key] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -11250,9 +11250,9 @@
|
|||||||
* // => { 'b': '2' }
|
* // => { 'b': '2' }
|
||||||
*/
|
*/
|
||||||
function omitBy(object, predicate) {
|
function omitBy(object, predicate) {
|
||||||
predicate = getIteratee(predicate);
|
predicate = getIteratee(predicate, 2);
|
||||||
return basePickBy(object, function(value) {
|
return basePickBy(object, function(value, key) {
|
||||||
return !predicate(value);
|
return !predicate(value, key);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11295,7 +11295,7 @@
|
|||||||
* // => { 'a': 1, 'c': 3 }
|
* // => { 'a': 1, 'c': 3 }
|
||||||
*/
|
*/
|
||||||
function pickBy(object, predicate) {
|
function pickBy(object, predicate) {
|
||||||
return object == null ? {} : basePickBy(object, getIteratee(predicate));
|
return object == null ? {} : basePickBy(object, getIteratee(predicate, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5785,6 +5785,7 @@
|
|||||||
func = _[methodName],
|
func = _[methodName],
|
||||||
isBy = /(^partition|By)$/.test(methodName),
|
isBy = /(^partition|By)$/.test(methodName),
|
||||||
isFind = /^find/.test(methodName),
|
isFind = /^find/.test(methodName),
|
||||||
|
isOmitPick = /^(?:omit|pick)By$/.test(methodName),
|
||||||
isSome = methodName == 'some';
|
isSome = methodName == 'some';
|
||||||
|
|
||||||
QUnit.test('`_.' + methodName + '` should provide the correct iteratee arguments', function(assert) {
|
QUnit.test('`_.' + methodName + '` should provide the correct iteratee arguments', function(assert) {
|
||||||
@@ -5806,7 +5807,7 @@
|
|||||||
expected[1] += '';
|
expected[1] += '';
|
||||||
}
|
}
|
||||||
if (isBy) {
|
if (isBy) {
|
||||||
expected.length = 1;
|
expected.length = isOmitPick ? 2 : 1;
|
||||||
}
|
}
|
||||||
assert.deepEqual(args, expected);
|
assert.deepEqual(args, expected);
|
||||||
}
|
}
|
||||||
@@ -5822,11 +5823,13 @@
|
|||||||
var array = [1];
|
var array = [1];
|
||||||
array[2] = 3;
|
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) {
|
if (isBy) {
|
||||||
expected = lodashStable.map(expected, function(args) {
|
expected = lodashStable.map(expected, function(args) {
|
||||||
return args.slice(0, 1);
|
return args.slice(0, isOmitPick ? 2 : 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (lodashStable.includes(objectMethods, methodName)) {
|
else if (lodashStable.includes(objectMethods, methodName)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user