Skip to content

Commit cc29bbd

Browse files
committed
feat: use Josh's solution that uses some method
1 parent ee12fc4 commit cc29bbd

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

14_contains/solution/contains-solution.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
const contains = function (initialObject, searchValue, queue = []) {
2-
if (initialObject !== null) queue.push(initialObject);
3-
if (initialObject === null && queue.length === 0) return false;
4-
const item = queue.shift();
5-
const values = Object.values(item);
1+
const contains = function (object, searchValue) {
2+
const values = Object.values(object);
63

74
// NaN === NaN evaluates to false
85
// Normally, we would have to do an explicit Number.isNaN() check to compare NaN equality
@@ -11,12 +8,12 @@ const contains = function (initialObject, searchValue, queue = []) {
118

129
const nestedObjects = values.filter(
1310
// typeof null === 'object' evaluates to true ¯\_(ツ)_/¯
14-
(value) => typeof value === "object" && value !== null,
11+
(value) => typeof value === "object" && value !== null
1512
);
1613

17-
const newQueue = queue.concat(nestedObjects);
18-
19-
return contains(null, searchValue, newQueue);
14+
return nestedObjects.some((nestedObject) =>
15+
contains(nestedObject, searchValue)
16+
);
2017
};
2118

2219
// Do not edit below this line

0 commit comments

Comments
 (0)