You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/63508c898d753754757bd5e3.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ dashedName: step-21
7
7
8
8
# --description--
9
9
10
-
By default, the `.sort()` method converts the elements of an array into strings, then sorts them alphabetically. This works well for strings, but not so well for numbers. For example, `10` comes before `2` when sorted as strings, but `2` comes before `10` when sorted as numbers.
10
+
By default, the `.sort()` method converts the elements of an array into strings, then sorts them alphabetically. The `.sort()` method mutates the original array. This works well for strings, but not so well for numbers. For example, `10` comes before `2` when sorted as strings, but `2` comes before `10` when sorted as numbers.
11
11
12
12
To fix this, you can pass in a callback function to the `.sort()` method. This function takes two arguments, which represent the two elements being compared. The function should return a value less than `0` if the first element should come before the second element, a value greater than `0` if the first element should come after the second element, and `0` if the two elements should remain in their current positions.
Copy file name to clipboardExpand all lines: curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/635090f47eb6d9563a6fed05.md
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,27 @@
1
1
---
2
2
id: 635090f47eb6d9563a6fed05
3
-
title: Step 26
3
+
title: Step 27
4
4
challengeType: 0
5
-
dashedName: step-26
5
+
dashedName: step-27
6
6
---
7
7
8
8
# --description--
9
9
10
10
Now it is time to apply what you have learned to the `getMedian` function.
11
11
12
-
Inside your `getMedian` function, check if the length of `array` is even. If it is, find the middle two numbers, calculate their mean, and return the result. If the length of `array` is odd, return the middle number.
12
+
Inside your `getMedian` function, check if the length of `sorted` is even. If it is, find the middle two numbers, calculate their mean, and return the result. If the length of `sorted` is odd, return the middle number.
13
13
14
14
Make sure to work with the `sorted` array to find the middle numbers.
15
15
16
16
Also if you need help, refer back to the previous few steps to see how to find the median for an array.
17
17
18
18
# --hints--
19
19
20
+
Your `getMedian` function should use `sorted` array.
Copy file name to clipboardExpand all lines: curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e79d15aae30fac58f48e.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
2
id: 6352e79d15aae30fac58f48e
3
-
title: Step 27
3
+
title: Step 28
4
4
challengeType: 0
5
-
dashedName: step-27
5
+
dashedName: step-28
6
6
---
7
7
8
8
# --description--
@@ -121,11 +121,11 @@ input {
121
121
constgetMean= (array) =>array.reduce((acc, el) => acc + el, 0) /array.length;
Copy file name to clipboardExpand all lines: curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e80e024e89111600edfb.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
2
id: 6352e80e024e89111600edfb
3
-
title: Step 28
3
+
title: Step 29
4
4
challengeType: 0
5
-
dashedName: step-28
5
+
dashedName: step-29
6
6
---
7
7
8
8
# --description--
@@ -119,11 +119,11 @@ input {
119
119
constgetMean= (array) =>array.reduce((acc, el) => acc + el, 0) /array.length;
Copy file name to clipboardExpand all lines: curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e93db104661305c5f658.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
2
id: 6352e93db104661305c5f658
3
-
title: Step 29
3
+
title: Step 30
4
4
challengeType: 0
5
-
dashedName: step-29
5
+
dashedName: step-30
6
6
---
7
7
8
8
# --description--
@@ -136,11 +136,11 @@ input {
136
136
constgetMean= (array) =>array.reduce((acc, el) => acc + el, 0) /array.length;
Copy file name to clipboardExpand all lines: curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e96d2604f813c656750b.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
2
id: 6352e96d2604f813c656750b
3
-
title: Step 30
3
+
title: Step 31
4
4
challengeType: 0
5
-
dashedName: step-30
5
+
dashedName: step-31
6
6
---
7
7
8
8
# --description--
@@ -108,14 +108,14 @@ input {
108
108
```js
109
109
constgetMean=array=>array.reduce((acc, el) => acc + el, 0) /array.length;
Copy file name to clipboardExpand all lines: curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ea3a5b79e614ee2282fd.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
2
id: 6352ea3a5b79e614ee2282fd
3
-
title: Step 36
3
+
title: Step 37
4
4
challengeType: 0
5
-
dashedName: step-36
5
+
dashedName: step-37
6
6
---
7
7
8
8
# --description--
@@ -130,11 +130,11 @@ input {
130
130
constgetMean= (array) =>array.reduce((acc, el) => acc + el, 0) /array.length;
Copy file name to clipboardExpand all lines: curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ebd3ab962c168a122e85.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
2
id: 6352ebd3ab962c168a122e85
3
-
title: Step 37
3
+
title: Step 38
4
4
challengeType: 0
5
-
dashedName: step-37
5
+
dashedName: step-38
6
6
---
7
7
8
8
# --description--
@@ -121,11 +121,11 @@ input {
121
121
constgetMean= (array) =>array.reduce((acc, el) => acc + el, 0) /array.length;
0 commit comments