|
1 | | -/* Calculate the mean of an array of numbers |
2 | | -
|
3 | | -In this kata, you will need to implement a function that calculates the mean of an array of numbers. |
4 | | -
|
5 | | -E.g. calculateMean([1, 2, 6]), target output: 3 |
6 | | -E.g. calculateMean([]) throws Error("calculateMean requires a non-empty array") |
7 | | -E.g. calculateMean("banana") throws Error("calculateMean requires an array of numbers") |
8 | | -
|
9 | | -There is no mean of an empty array, and a string isn't an array of numbers, so |
10 | | -calculateMean should throw rather than return a value. This is the same problem |
11 | | -calculateMedian solves in the prep and in the fix directory. |
12 | | -
|
13 | | -You should implement this function in mean.js, and add tests for it in this file. |
14 | | -
|
15 | | -We have set things up already so that this file can see your function from the other file. |
16 | | -*/ |
17 | | - |
18 | 1 | const calculateMean = require("./mean.js"); |
19 | 2 |
|
20 | | -// Acceptance criteria: |
21 | | - |
22 | | -// Given an array of numbers |
23 | | -// When passed to calculateMean |
24 | | -// Then it should return their mean |
25 | | -// Delete this test.todo and replace it with a test. |
26 | 3 | test("given [1, 2, 6], returns 3", () => { |
27 | 4 | expect(calculateMean([1, 2, 6])).toBe(3); |
28 | 5 | }); |
@@ -52,26 +29,3 @@ test("throws for an array containing. a non-number", () => { |
52 | 29 | new Error("calculateMean requires a array of numbers") |
53 | 30 | ); |
54 | 31 | }); |
55 | | -// Given an array with a single number |
56 | | -// When passed to calculateMean |
57 | | -// Then it should return that number |
58 | | - |
59 | | -// Given an array containing negative or decimal numbers |
60 | | -// When passed to calculateMean |
61 | | -// Then it should return the correct mean |
62 | | - |
63 | | -// Given an empty array |
64 | | -// When passed to calculateMean |
65 | | -// Then it should throw Error("calculateMean requires a non-empty array") |
66 | | - |
67 | | -// Given a value that isn't an array, e.g. "banana", 42, null or {} |
68 | | -// When passed to calculateMean |
69 | | -// Then it should throw Error("calculateMean requires an array of numbers") |
70 | | - |
71 | | -// Given no argument at all |
72 | | -// When passed to calculateMean |
73 | | -// Then it should throw Error("calculateMean requires an array of numbers") |
74 | | - |
75 | | -// Given an array containing a non-number value, e.g. [1, "2", 3] |
76 | | -// When passed to calculateMean |
77 | | -// Then it should throw Error("calculateMean requires an array of numbers") |
0 commit comments