Skip to content

Commit 0dddbf3

Browse files
committed
fixed contains function
1 parent 611d247 commit 0dddbf3

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

Sprint-2/implement/contains.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
function contains(obj, name) {
2-
if (typeof obj == "object" || obj !== null || Object.keys(obj).length !== 0)
3-
return Object.hasOwn(obj, name);
4-
return false;
2+
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
3+
return false;
4+
}
5+
return Object.hasOwn(obj, name);
56
}
67

78
module.exports = contains;

Sprint-2/implement/contains.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ test("given an object with properties, returns false when passed to contains wit
4545
// Given invalid parameters like an array
4646
// When passed to contains
4747
// Then it should return false or throw an error
48-
test("given invalid parameters, returns false or throws an error", () => {
48+
test("given invalid parameters (array), returns false or throws an error", () => {
4949
expect(contains(["gitName", "position"], "gitName")).toEqual(false);
5050
});
51+
52+
test("given invalid parameters (like null or undefined), returns false or throws an error", () => {
53+
expect(contains(null, "gitName")).toEqual(false);
54+
});

0 commit comments

Comments
 (0)