Skip to content

Commit 44ec087

Browse files
committed
Sprint-2
1 parent aa7da66 commit 44ec087

File tree

13 files changed

+111
-21
lines changed

13 files changed

+111
-21
lines changed

Sprint-2/debug/address.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ const address = {
1111
country: "England",
1212
postcode: "XYZ 123",
1313
};
14-
15-
console.log(`My house number is ${address[0]}`);
14+
//the fixed two lines
15+
console.log(`My house number is ${address.houseNumber}`);
16+
console.log(`My house number is ${address["houseNumber"]}`);

Sprint-2/debug/author.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const author = {
1010
age: 40,
1111
alive: true,
1212
};
13-
14-
for (const value of author) {
13+
//changed code at line 14
14+
for (const value of Object.values(author)) {
1515
console.log(value);
1616
}
17+

Sprint-2/debug/recipe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ const recipe = {
1212

1313
console.log(`${recipe.title} serves ${recipe.serves}
1414
ingredients:
15-
${recipe}`);
15+
${recipe.ingredients.join(", ")}`);

Sprint-2/implement/contains.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1-
function contains() {}
1+
function contains(object, property) {
2+
if (Object.keys(object).length === 0 ){
3+
return false;
4+
}
5+
if (object.hasOwnProperty(property)){
6+
return true;
7+
}
8+
else{
9+
return false;
10+
}
11+
12+
}
213

314
module.exports = contains;
15+

Sprint-2/implement/contains.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,37 @@ as the object doesn't contains a key of 'c'
2020
// Given an empty object
2121
// When passed to contains
2222
// Then it should return false
23-
test.todo("contains on empty object returns false");
23+
//test.todo("contains on empty object returns false");
24+
test("given an empty object, it should return false", () => {
25+
const currentOutput = contains({});
26+
const targetOutput = false;
27+
expect(currentOutput).toEqual(targetOutput);
28+
});
2429

2530
// Given an object with properties
2631
// When passed to contains with an existing property name
2732
// Then it should return true
33+
test("given an object with properties, when passed to contains with an existing property name it should return true", () => {
34+
const currentOutput = contains({a: 1, b: 2}, 'a') ;
35+
const targetOutput = true;
36+
expect(currentOutput).toEqual(targetOutput);
37+
});
38+
2839

2940
// Given an object with properties
3041
// When passed to contains with a non-existent property name
3142
// Then it should return false
43+
test("given an object with properties, when passed to contains with a non-existent property name it should return false", () => {
44+
const currentOutput = contains({a: 1, b: 2}, 'c') ;
45+
const targetOutput = false;
46+
expect(currentOutput).toEqual(targetOutput);
47+
});
3248

3349
// Given invalid parameters like an array
3450
// When passed to contains
3551
// Then it should return false or throw an error
52+
test("given ivalid parameters like an array, when passed to contains it should return false throw an error", () => {
53+
const currentOutput = contains([1,'a'], 'c') ;
54+
const targetOutput = false;
55+
expect(currentOutput).toEqual(targetOutput);
56+
});

Sprint-2/implement/lookup.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function createLookup() {
2-
// implementation here
1+
function createLookup(country_currency) {
2+
let obj = Object.fromEntries(country_currency);
3+
return obj
34
}
45

56
module.exports = createLookup;

Sprint-2/implement/lookup.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
const createLookup = require("./lookup.js");
22

3-
test.todo("creates a country currency code lookup for multiple codes");
3+
test("creates a country currency code lookup for multiple codes", () => {
4+
const currentOutput = createLookup([['US', 'USD'], ['CA', 'CAD']]) ;
5+
const targetOutput = {
6+
'US': 'USD',
7+
'CA': 'CAD'
8+
};
9+
expect(currentOutput).toEqual(targetOutput);
10+
});
411

512
/*
613

Sprint-2/implement/querystring.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ function parseQueryString(queryString) {
33
if (queryString.length === 0) {
44
return queryParams;
55
}
6-
const keyValuePairs = queryString.split("&");
6+
const keyValuePairs = queryString.split("&");//method split gives us an array
77

88
for (const pair of keyValuePairs) {
9-
const [key, value] = pair.split("=");
9+
const indexForKey = pair.indexOf('=');
10+
const key = pair.substring(0,indexForKey);
11+
const value = pair.substring(indexForKey+1, pair.length)
12+
13+
1014
queryParams[key] = value;
1115
}
1216

Sprint-2/implement/querystring.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ test("parses querystring values containing =", () => {
1010
"equation": "x=y+1",
1111
});
1212
});
13+
test("must return empty object if query string is empty", () => {
14+
expect(parseQueryString("")).toEqual({ });
15+
});

Sprint-2/implement/tally.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1-
function tally() {}
1+
function tally(array) {
2+
if (!Array.isArray(array)){ //check if array is array
3+
throw new Error("Invalid input");
4+
}
5+
if (array.length === 0 ){
6+
return {};
7+
}
8+
const obj = {}
9+
for (let item of array){
10+
if (obj[item]){
11+
obj[item]+=1;
12+
}
13+
else{
14+
obj[item]=1;
15+
}
16+
}
17+
return obj
18+
}
219

320
module.exports = tally;

0 commit comments

Comments
 (0)