1- /* Describe the median, or explain why there isn't one
2-
3- calculateMedian is given to you at the top of describe-median.js. It throws
4- when it can't calculate a median. Don't change it.
5-
6- Implement describeMedian, which calls calculateMedian and returns a sentence
7- instead of crashing.
8-
9- E.g. describeMedian([1, 2, 3]), target output: "The median is 2"
10- E.g. describeMedian([]), target output: "Could not calculate a median: calculateMedian requires a non-empty array"
11-
12- You'll need a try/catch block for this. The catch block must use the error's
13- message, so the caller can see what went wrong.
14- */
15-
161const describeMedian = require ( "./describe-median.js" ) ;
172
18- // Acceptance criteria:
193
20- // Given an array of numbers
21- // When passed to describeMedian
22- // Then it should return "The median is " followed by the median
23- // Delete this test.todo and replace it with a test.
244test ( 'given [1, 2, 3], returns "The median is 2"' , ( ) => {
25- expect ( describeMedian ( [ 1 , 2 , 3 ] ) ) . toBe ( "Tne median is 2" ) ;
5+ expect ( describeMedian ( [ 1 , 2 , 3 ] ) ) . toBe ( "The median is 2" ) ;
266} ) ;
277
288test ( "returns a sentence for an empty array" , ( ) => {
@@ -36,11 +16,3 @@ test("return a sentence for a non-array", () => {
3616 "Could not calculate a median: calculateMedian requires an array of numbers"
3717 ) ;
3818} ) ;
39-
40- // Given an empty array
41- // When passed to describeMedian
42- // Then it should return "Could not calculate a median: calculateMedian requires a non-empty array"
43-
44- // Given something that isn't an array of numbers, e.g. "banana"
45- // When passed to describeMedian
46- // Then it should return "Could not calculate a median: calculateMedian requires an array of numbers"
0 commit comments