Skip to content

Commit 34f16f3

Browse files
authored
Refactor contains function to improve type checks
1 parent 9ca3f78 commit 34f16f3

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎Sprint-2/implement/contains.js‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
function contains(obj, prop) {
2-
const notArray = !Array.isArray(obj);
3-
if (obj === null || Array.isArray(obj) || obj === Number || obj === undefined) {
4-
return false;
5-
}
6-
return obj.hasOwnProperty(prop);
1+
function contains(value, prop) {
2+
const isObject = (value) => {
3+
return typeof value === 'object'
4+
&& value !== null
5+
&& !Array.isArray(value)
6+
&& !(value instanceof RegExp)
7+
&& !(value instanceof Date)
8+
&& !(value instanceof Set)
9+
&& !(value instanceof Map)
10+
}
11+
if (!isObject(value)) {
12+
return false;
13+
} return value.hasOwnProperty(prop);
714
}

0 commit comments

Comments
 (0)