Skip to content

Commit 360078c

Browse files
committed
feat/ null check
1 parent 4873c5a commit 360078c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

14_contains/solution/contains-solution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const contains = function(obj, searchValue) {
44
// NaN !== NaN, so we would usually have to do an explicit check with Math.isNaN to test for it. However, Array.prototype.includes handles that for us
55
if (values.includes(searchValue)) return true;
66

7-
const nestedObjects = values.filter((value) => typeof value === 'object');
7+
const nestedObjects = values.filter((value) => typeof value === 'object' && value !== null);
88
for (const nestedObject of nestedObjects) {
99
return contains(nestedObject, searchValue);
1010
}

14_contains/solution/contains-solution.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('contains', () => {
77
info: {
88
duplicate: 'e',
99
magicNumber: 44,
10+
empty: null,
1011
stuff: {
1112
thing: {
1213
banana: NaN,
@@ -47,4 +48,8 @@ describe('contains', () => {
4748
test('true if NaN is a value within the object', () => {
4849
expect(contains(object, NaN)).toBe(true);
4950
});
51+
52+
test('false if the provided value exists and is null', () => {
53+
expect(contains(object, null)).toBe(true);
54+
});
5055
});

0 commit comments

Comments
 (0)