Skip to content

Commit 30e08c8

Browse files
authored
Misc tweaks to sprint 2 (#48)
* Add package-lock.json * Misc copy edits and typo fixes * Add extension to in-sprint querystring parsing
1 parent f9d44f5 commit 30e08c8

File tree

15 files changed

+3829
-33
lines changed

15 files changed

+3829
-33
lines changed

Sprint-2/implement/contains.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ const contains = require("./contains.js");
44
Implement a function called contains that checks an object contains a
55
particular property
66
7-
E.g. contains({ a : 1, b: 2 },'a') // returns true
7+
E.g. contains({a: 1, b: 2}, 'a') // returns true
88
as the object contains a key of 'a'
99
10-
E.g. contains({a : 1, b : 2},'c') // returns false
10+
E.g. contains({a: 1, b: 2}, 'c') // returns false
1111
as the object doesn't contains a key of 'c'
1212
*/
1313

@@ -20,6 +20,7 @@ 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");
2324

2425
// Given an object with properties
2526
// When passed to contains with an existing property name
@@ -29,6 +30,6 @@ as the object doesn't contains a key of 'c'
2930
// When passed to contains with a non-existent property name
3031
// Then it should return false
3132

32-
// Given invalid parameters like arrays
33+
// Given invalid parameters like an array
3334
// When passed to contains
3435
// Then it should return false or throw an error

Sprint-2/implement/lookup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
function createLookup() {
22
// implementation here
33
}
4+
5+
module.exports = createLookup;

Sprint-2/implement/lookup.test.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
// ======= Test suite is provided below... =======
2-
3-
test("converts a single pair of currency codes", () => {
4-
expect(createLookup([["GB", "GBP"]])).toEqual({
5-
GB: "GBP",
6-
});
7-
expect(createLookup([["DE", "EUR"]])).toEqual({
8-
DE: "EUR",
9-
});
10-
});
1+
const createLookup = require("./lookup.js");
112

123
test.todo("creates a country currency code lookup for multiple codes");
134

Sprint-2/implement/querystring.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function parseQueryString(queryString) {
2+
const queryParams = {};
3+
if (queryString.length === 0) {
4+
return queryParams;
5+
}
6+
const keyValuePairs = queryString.split("&");
7+
8+
for (const pair of keyValuePairs) {
9+
const [key, value] = pair.split("=");
10+
queryParams[key] = value;
11+
}
12+
13+
return queryParams;
14+
}
15+
16+
module.exports = parseQueryString;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// In the prep, we implemented a function to parse query strings.
2+
// Unfortunately, it contains several bugs!
3+
// Below is one test case for an edge case the implementation doesn't handle well.
4+
// Fix the implementation for this test, and try to think of as many other edge cases as possible - write tests and fix those too.
5+
6+
const parseQueryString = require("./querystring.js")
7+
8+
test("parses querystring values containing =", () => {
9+
expect(parseQueryString("equation=x=y+1")).toEqual({
10+
"equation": "x=y+1",
11+
});
12+
});

Sprint-2/implement/tally.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function tally() {}
2+
3+
module.exports = tally;

Sprint-2/implement/tally.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const tally = require("./tally.js");
2+
13
/**
24
* tally array
35
*
@@ -8,8 +10,8 @@
810
* For example:
911
*
1012
* tally(['a']), target output: { a: 1 }
11-
* tally(['a','a','a']), target output: { a: 3 }
12-
* tally(['a','a','b','c']), target output: { a : 2, b: 1, c: 1 }
13+
* tally(['a', 'a', 'a']), target output: { a: 3 }
14+
* tally(['a', 'a', 'b', 'c']), target output: { a : 2, b: 1, c: 1 }
1315
*/
1416

1517
// Acceptance criteria:
@@ -21,6 +23,7 @@
2123
// Given an empty array
2224
// When passed to tally
2325
// Then it should return an empty object
26+
test.todo("tally on an empty array returns an empty object");
2427

2528
// Given an array with duplicate items
2629
// When passed to tally

Sprint-2/interpret/invert.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ function invert(obj) {
2525
// c) What does Object.entries return? Why is it needed in this program?
2626

2727
// d) Explain why the current return value is different from the target output
28+
29+
// e) Fix the implementation of invert (and write tests to prove it's fixed!)

0 commit comments

Comments
 (0)