Tell us what’s happening:
Step 59 asks the user to fix that the .sort() method is mutating the array which it is called on by adding a .slice(), but this was already addressed in Step 26 by replacing the .sort() method with a .toSorted() method. You can of course get past this final step by reverting to the .sort() method and then following the instructions of Step 59, but you really shouldn’t have to.
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const getMedian = (array) => {
const sorted = array.toSorted((a, b) => a - b);
const median =
sorted.length % 2 === 0
? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]])
: sorted[Math.floor(sorted.length / 2)];
return median;
}
// User Editable Region
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Challenge Information:
Learn Advanced Array Methods by Building a Statistics Calculator - Step 59