Skip to content

Commit 36938ec

Browse files
committed
contains function and testing contains function
1 parent 355bdc4 commit 36938ec

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

Sprint-2/implement/contains.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1-
function contains() {}
1+
function contains(object, property) {
2+
for (const key of Object.keys(object)) {
3+
if (key === property) {
4+
console.log(`${object[key]}`);
5+
return true;
6+
}
7+
}
8+
return false;
9+
}
10+
11+
const profile = {
12+
name: "Gita",
13+
age: 22,
14+
school: "Leith Academy",
15+
};
16+
17+
const result = contains(profile, "age");
18+
console.log(result);
219

320
module.exports = contains;

Sprint-2/implement/contains.test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,54 @@ as the object doesn't contains a key of 'c'
1616
// Given a contains function
1717
// When passed an object and a property name
1818
// Then it should return true if the object contains the property, false otherwise
19+
describe("edge cases of the contains function", () => {
20+
test("contains an object and property and returns true", () => {
21+
const currentOutput = contains({ property: "value" }, "property");
22+
const targetOutput = true;
23+
expect(currentOutput).toEqual(targetOutput);
24+
});
25+
});
1926

2027
// Given an empty object
2128
// When passed to contains
2229
// Then it should return false
23-
test.todo("contains on empty object returns false");
30+
describe("edge cases of the contains function", () => {
31+
test("contains on empty object returns false", () => {
32+
const currentOutput = contains({}, "property");
33+
const targetOutput = false;
34+
expect(currentOutput).toEqual(targetOutput);
35+
});
36+
});
2437

2538
// Given an object with properties
2639
// When passed to contains with an existing property name
2740
// Then it should return true
41+
describe("edge cases of the contains function", () => {
42+
test("contains an object and property and returns true", () => {
43+
const currentOutput = contains({ property: "value" }, "property");
44+
const targetOutput = true;
45+
expect(currentOutput).toEqual(targetOutput);
46+
});
47+
});
2848

2949
// Given an object with properties
3050
// When passed to contains with a non-existent property name
3151
// Then it should return false
52+
describe("edge cases of the contains function", () => {
53+
test("contains an object and property and returns true", () => {
54+
const currentOutput = contains({ property: "value" }, "lava");
55+
const targetOutput = false;
56+
expect(currentOutput).toEqual(targetOutput);
57+
});
58+
});
3259

3360
// Given invalid parameters like an array
3461
// When passed to contains
3562
// Then it should return false or throw an error
63+
describe("edge cases of the contains function", () => {
64+
test("contains an object and property and returns true", () => {
65+
const currentOutput = contains([], "property");
66+
const targetOutput = false;
67+
expect(currentOutput).toEqual(targetOutput);
68+
});
69+
});

Sprint-2/implement/lookup.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
function createLookup() {
2-
// implementation here
1+
function createLookup(arr) {
2+
// const arr1 =
3+
// const arr2 =
4+
for (let i = 0; i < arr.length; i++) {
5+
let newArray = countryCurrencyPairs[i];
6+
console.log(newArray);
7+
}
8+
return newArray;
39
}
410

11+
const countryCurrencyPairs = [
12+
["US", "USD"],
13+
["CA", "CAD"],
14+
];
15+
const result = createLookup(countryCurrencyPairs);
516
module.exports = createLookup;

0 commit comments

Comments
 (0)