8000 Add deep functionality for `_.omit` and `_.pick`. (#2794) · lodash/lodash@9ac729e · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ac729e

Browse files
avivrjdalton
authored andcommitted
Add deep functionality for _.omit and _.pick. (#2794)
1 parent 6d951cc commit 9ac729e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lodash.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,7 +3757,7 @@
37573757
function basePick(object, props) {
37583758
object = Object(object);
37593759
return basePickBy(object, props, function(value, key) {
3760-
return key in object;
3760+
return hasIn(object, key);
37613761
});
37623762
}
37633763

@@ -3777,10 +3777,10 @@
37773777

37783778
while (++index < length) {
37793779
var key = props[index],
3780-
value = object[key];
3780+
value = get(object, key);
37813781

37823782
if (predicate(value, key)) {
3783-
baseAssignValue(result, key, value);
3783+
set(result, key, value);
37843784
}
37853785
}
37863786
return result;

test/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16386,6 +16386,12 @@
1638616386

1638716387
assert.deepEqual(_.omit({ '0': 'a' }, 0), {});
1638816388
});
16389+
16390+
QUnit.test('should work with deep properties', function(assert) {
16391+
assert.expect(1);
16392+
16393+
assert.deepEqual(_.omit({ 'a': 1, 'b': { 'c': 2 } }, 'b.c'), { 'a': 1, 'b': {} });
16394+
});
1638916395
}());
1639016396

1639116397
/*--------------------------------------------------------------------------*/
@@ -17608,6 +17614,12 @@
1760817614

1760917615
assert.deepEqual(_.pick({ '0': 'a', '1': 'b' }, 0), { '0': 'a' });
1761017616
});
17617+
17618+
QUnit.test('should work with deep properties', function(assert) {
17619+
assert.expect(1);
17620+
17621+
assert.deepEqual(_.pick({ 'a': 1, 'b': { 'c': 2 } }, 'b.c'), { 'b': { 'c': 2 } });
17622+
});
1761117623
}());
1761217624

1761317625
/*--------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)
0