Skip to content

Commit 4c30695

Browse files
Merge branch 'main' into coursework/sprint-3-alarmclock
2 parents 0316d66 + de6889c commit 4c30695

3 files changed

Lines changed: 48 additions & 11 deletions

File tree

‎Sprint-1/implement/dedupe.test.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Dedupe Array
66
77
In this kata, you will need to deduplicate the elements of an array
88
9-
E.g. dedupe(['a','a','a','b','b','c']) target output: ['a','b','c']
10-
E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) target output: [5, 1, 2, 3, 8]
11-
E.g. dedupe([1, 2, 1]) target output: [1, 2]
9+
E.g. dedupe(['a','a','a','b','b','c']) returns ['a','b','c']
10+
E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) returns [5, 1, 2, 3, 8]
11+
E.g. dedupe([1, 2, 1]) returns [1, 2]
1212
*/
1313

1414
// Acceptance Criteria:
@@ -22,6 +22,7 @@ test.todo("given an empty array, it returns an empty array");
2222
// When passed to the dedupe function
2323
// Then it should return a copy of the original array
2424

25-
// Given an array with strings or numbers
25+
// Given an array of strings or numbers
2626
// When passed to the dedupe function
27-
// Then it should remove the duplicate values, preserving the first occurence of each element
27+
// Then it should return a new array with duplicates removed while preserving the
28+
// first occurrence of each element from the original array.

‎Sprint-1/readme.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ In this section, you'll have a function and some tests. The function isn't worki
2020

2121
- Run the tests - to run the tests for the `fix` directory you can `cd` into `Sprint-1` and run `npm test -- fix`.
2222
- Interpret the test feedback
23-
- Fix the tests
23+
- Fix the function to make it pass the tests
2424

2525
## 🔨 Implement
2626

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
11
// In the prep, we implemented a function to parse query strings.
22
// 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.
3+
// Below are some test cases the implementation doesn't handle well.
4+
// Fix the implementation for these tests, and try to think of as many other edge cases as possible - write tests and fix those too.
55

66
const parseQueryString = require("./querystring.js")
77

8-
test("parses querystring values containing =", () => {
9-
expect(parseQueryString("equation=x=y+1")).toEqual({
10-
"equation": "x=y+1",
8+
test("should parse values containing '='", () => {
9+
expect(parseQueryString("equation=a=b-2")).toEqual({
10+
equation: "a=b-2",
11+
});
12+
});
13+
14+
test("should ignore empty key-value pairs", () => {
15+
expect(parseQueryString("key1=value1&&key2=value2&")).toEqual({
16+
key1: "value1",
17+
key2: "value2",
18+
});
19+
});
20+
21+
test("should accept empty string as key or as value", () => {
22+
expect(parseQueryString("=value")).toEqual({ "": "value" });
23+
expect(parseQueryString("key")).toEqual({ key: "" });
24+
expect(parseQueryString("key=")).toEqual({ key: "" });
25+
expect(parseQueryString("=")).toEqual({ "": "" });
26+
});
27+
28+
test("should decode percent-encoded characters", () => {
29+
expect(parseQueryString("%24half=1%2F2")).toEqual({
30+
$half: "1/2",
31+
});
32+
});
33+
34+
test("should replace '+' by ' '", () => {
35+
expect(parseQueryString("full+name=John+Doe")).toEqual({
36+
"full name": "John Doe",
37+
});
38+
});
39+
40+
// Stretch exercise: Handling query strings that contain identical keys
41+
42+
// Delete this test if you are not working on this optional case
43+
test("should store values of a key in an array when the key has 2 or more values", () => {
44+
expect(parseQueryString("key=value1&key=value2&key=value3&foo=bar")).toEqual({
45+
key: ["value1", "value2", "value3"],
46+
foo: "bar",
1147
});
1248
});

0 commit comments

Comments
 (0)