We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c6076ed commit 45d4be7Copy full SHA for 45d4be7
Sprint-1/fix/median.js
@@ -14,8 +14,8 @@ function calculateMedian(list) {
14
15
if (numbers.length === 0) return null; // Must have at least one number
16
17
- const sorted = [...numbers].sort((a, b) => a - b);
18
- // numeric array copied before sorting in ascending order so that original array not mutated
+ const sorted = numbers.slice().sort((a, b) => a - b);
+ // replaced unnecessary array clone
19
20
const mid = Math.floor(sorted.length / 2); // math.floor gives the correct index
21
if (sorted.length % 2 === 1) {
0 commit comments