Skip to content

Commit f9d44f5

Browse files
authored
Fixes for Sprint 1 (#47)
* Fix up typos in exercises * Update a bunch of week-1s to Sprint-1s * Use toEqual not toBe * Add a bit more scaffolding for exports and requires, as we currently don't reliably teach this. * Add a few more edge cases to test for * Move root package.json to Sprint-3 directory, because that's the set of tests it hard-codes as modules, and rework instructions to not assume you're installing stuff in the root of the repo. * Change refactor exercises from implementing `find` to implementing `includes` - because `find` returns the index, I would consider it better implemented with a for-with-index loop than a for..of loop. `includes` does not share this property.
1 parent 461add5 commit f9d44f5

15 files changed

+3874
-8764
lines changed

Sprint-1/fix/median.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Fix this implementation
22
// Start by running the tests for this function
3-
// If you're in the week-1 directory, you can run npm test -- fix to run the tests in the fix directory
3+
// If you're in the Sprint-1 directory, you can run `npm test -- fix` to run the tests in the fix directory
44

55
function calculateMedian(list) {
66
const middleIndex = Math.floor(list.length / 2);

Sprint-1/fix/median.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ const calculateMedian = require("./median.js");
88

99
describe("calculateMedian", () => {
1010
test("returns the median for odd length array", () => {
11-
expect(calculateMedian([1, 2, 3])).toBe(2);
12-
expect(calculateMedian([1, 2, 3, 4, 5])).toBe(3);
11+
expect(calculateMedian([1, 2, 3])).toEqual(2);
12+
expect(calculateMedian([1, 2, 3, 4, 5])).toEqual(3);
1313
});
1414

1515
test("returns the average of middle values for even length array", () => {
16-
expect(calculateMedian([1, 2, 3, 4])).toBe(2.5);
17-
expect(calculateMedian([1, 2, 3, 4, 5, 6])).toBe(3.5);
16+
expect(calculateMedian([1, 2, 3, 4])).toEqual(2.5);
17+
expect(calculateMedian([1, 2, 3, 4, 5, 6])).toEqual(3.5);
1818
});
1919

2020
test("doesn't modify the input", () => {

Sprint-1/implement/dedupe.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ In this kata, you will need to deduplicate the elements of an array
88
99
E.g. dedupe(['a','a','a','b','b','c']) target output: ['a','b','c']
1010
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]
1112
*/
1213

1314
// Acceptance Criteria:
@@ -23,4 +24,4 @@ test.todo("given an empty array, it returns an empty array");
2324

2425
// Given an array with strings or numbers
2526
// When passed to the dedupe function
26-
// Then it should remove the duplicate values
27+
// Then it should remove the duplicate values, preserving the first occurence of each element

Sprint-1/implement/max.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function findMax(elements) {
2+
}
3+
4+
module.exports = findMax;

Sprint-1/implement/max.test.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
/* Find the maximum element of an array of numbers
22
3-
In this kata, you will need to implement a function that sums the numerical elements of an array
3+
In this kata, you will need to implement a function that find the largest numerical element of an array.
44
55
E.g. max([30, 50, 10, 40]), target output: 50
66
E.g. max(['hey', 10, 'hi', 60, 10]), target output: 60 (sum ignores any non-numerical elements)
7+
8+
You should implement this function in max.js, and add tests for it in this file.
9+
10+
We have set things up already so that this file can see your function from the other file.
711
*/
812

13+
const findMax = require("./max.js");
14+
915
// Given an empty array
1016
// When passed to the max function
1117
// Then it should return -Infinity
18+
// Delete this test.todo and replace it with a test.
1219
test.todo("given an empty array, returns -Infinity");
1320

1421
// Given an array with one number
@@ -19,10 +26,18 @@ test.todo("given an empty array, returns -Infinity");
1926
// When passed to the max function
2027
// Then it should return the largest number overall
2128

29+
// Given an array with just negative numbers
30+
// When passed to the max function
31+
// Then it should return the closest one to zero
32+
2233
// Given an array with decimal numbers
2334
// When passed to the max function
2435
// Then it should return the largest decimal number
2536

2637
// Given an array with non-number values
2738
// When passed to the max function
2839
// Then it should return the max and ignore non-numeric values
40+
41+
// Given an array with only non-number values
42+
// When passed to the max function
43+
// Then it should return the least surprising value given how it behaves for all other inputs

Sprint-1/implement/sum.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function sum(elements) {
2+
}
3+
4+
module.exports = sum;

Sprint-1/implement/sum.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ E.g. sum([10, 20, 30]), target output: 60
66
E.g. sum(['hey', 10, 'hi', 60, 10]), target output: 80 (ignore any non-numerical elements)
77
*/
88

9+
const sum = require("./sum.js");
10+
911
// Acceptance Criteria:
1012

1113
// Given an empty array
1214
// When passed to the sum function
1315
// Then it should return 0
16+
test.todo("given an empty array, returns 0")
1417

1518
// Given an array with just one number
1619
// When passed to the sum function
@@ -27,3 +30,7 @@ E.g. sum(['hey', 10, 'hi', 60, 10]), target output: 80 (ignore any non-numerical
2730
// Given an array containing non-number values
2831
// When passed to the sum function
2932
// Then it should ignore the non-numerical values and return the sum of the numerical elements
33+
34+
// Given an array with only non-number values
35+
// When passed to the sum function
36+
// Then it should return the least surprising value given how it behaves for all other inputs

0 commit comments

Comments
 (0)