Skip to content

Commit db402f7

Browse files
committed
Merge branch 'feat/exercise_14' of https://github.com/nikitarevenco/javascript-exercises into feat/exercise_14
2 parents 90afe10 + cd0a557 commit db402f7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

14_contains/solution/contains-solution.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
const contains = function(current, search) {
2-
if (Object.values(current).includes(search)) return true;
1+
const contains = function(obj, searchValue) {
2+
const values = Object.values(obj);
3+
if (values.includes(searchValue)) return true;
34

4-
for (const nestedObject of Object.values(current).filter((value) => typeof value === 'object')) {
5-
return contains(nestedObject, search)
5+
const nestedObjects = values.filter((value) => typeof value === 'object');
6+
for (const nestedObject of nestedObjects) {
7+
return contains(nestedObject, searchValue);
68
}
7-
8-
return false
9+
10+
return false;
911
};
1012

1113
// Do not edit below this line

0 commit comments

Comments
 (0)