Skip to content

Commit e1a49b1

Browse files
committed
reimplement contains and add test case for array inputs
1 parent ffd8465 commit e1a49b1

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Sprint-2/implement/contains.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function isObject(item) {
44

55
function contains(object, key) {
66
if (isObject(object)) {
7-
return Object.keys(object).includes(key);
7+
return key in object;
88
}
99
throw new TypeError("Item is not plain object, Date, or Map");
1010
}

Sprint-2/implement/contains.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ test("given an object, and property that does not exist in object, should return
4343
// Then it should return false or throw an error
4444
test("given invalid parameter, like an array, should return false or throw error", () => {
4545
expect(() => contains(22, "a")).toThrow(TypeError);
46+
expect(() => contains([], "a")).toThrow(TypeError);
4647
});

0 commit comments

Comments
 (0)