Skip to content

Commit 0291dfa

Browse files
committed
implement contains function
1 parent 2488a71 commit 0291dfa

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎Sprint-2/implement/contains.js‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1-
function contains() {}
1+
function contains(object, propertyName) {
2+
if (typeof object !== "object" || object === null || Array.isArray(object)) {
3+
throw new Error("Input should be an object");
4+
}
5+
const keysInObject = Object.keys(object);
6+
if (keysInObject.includes(propertyName)) {
7+
return true;
8+
} else {
9+
return false;
10+
}
11+
}
212

313
module.exports = contains;
14+
15+
/*
16+
Implement a function called contains that checks an object contains a
17+
particular property
18+
19+
E.g. contains({a: 1, b: 2}, 'a') // returns true
20+
as the object contains a key of 'a'
21+
22+
E.g. contains({a: 1, b: 2}, 'c') // returns false
23+
as the object doesn't contains a key of 'c'
24+
*/

0 commit comments

Comments
 (0)