Skip to content

Commit cd0a557

Browse files
nik-revmao-sz
andauthored
feat/ improve readability of solution
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
1 parent 59c6768 commit cd0a557

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)