1
+ // const { calculateMedian } = require("./median");
1
2
const calculateMedian = require ( "./median" ) ;
3
+
4
+
2
5
const calculateMean = require ( "./mean" ) ;
6
+ // const { calculateMean } = require("./mean");
3
7
4
8
test ( "calculates the median of a list of odd length" , ( ) => {
5
9
const list = [ 10 , 20 , 30 , 50 , 60 ] ;
@@ -9,6 +13,22 @@ test("calculates the median of a list of odd length", () => {
9
13
expect ( currentOutput ) . toEqual ( targetOutput ) ;
10
14
} )
11
15
16
+ test ( "calculates the median of an odd-length array" , ( ) => {
17
+ const list = [ 3 , 50 , 7 ] ;
18
+ const currentOutput = calculateMedian ( list ) ; // sorted = [3, 7, 50], median = 7
19
+ const expectedOutput = 7 ;
20
+
21
+ expect ( currentOutput ) . toEqual ( expectedOutput ) ;
22
+ } ) ;
23
+
24
+ test ( "calculates the median of a list of odd length" , ( ) => {
25
+ const list = [ 10 , 20 , 30 , 40 ] ;
26
+ const currentOutput = calculateMedian ( list ) ;
27
+ const targetOutput = 25 ;
28
+
29
+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
30
+ } )
31
+
12
32
// Both functions access the same array
13
33
// because JavaScript passes objects and
14
34
// arrays by reference — they all point to the same memory location.
@@ -18,4 +38,9 @@ const median = calculateMedian(salaries);
18
38
const mean = calculateMean ( salaries ) ;
19
39
console . log ( salaries , "<--- salaries input before we call calculateMean" ) ;
20
40
console . log ( `The median salary is ${ median } ` ) ;
21
- console . log ( `The mean salary is ${ mean } ` ) ;
41
+ console . log ( `The mean salary is ${ mean } ` ) ;
42
+
43
+
44
+
45
+
46
+
0 commit comments