Skip to content

Commit 9ca3f78

Browse files
authored
Improve contains function property check
Refactor contains function to handle null, undefined, and Number types.
1 parent aff50e0 commit 9ca3f78

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎Sprint-2/implement/contains.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
function contains(obj, prop) {
2-
if (Array.isArray(obj)) {
3-
return false; // returns false if an object contains an array
4-
}
2+
const notArray = !Array.isArray(obj);
3+
if (obj === null || Array.isArray(obj) || obj === Number || obj === undefined) {
4+
return false;
5+
}
56
return obj.hasOwnProperty(prop);
67
}

0 commit comments

Comments
 (0)