Declare a median variable. Using the ternary operator, check if the length of array is even. If the length of array is even, find the two middle numbers and calculate the mean of those numbers. If the length of array is odd, find the middle number and assign it to the median variable.
The hint has this part that i don’t understand:
Your first argument should be the value of sorted at array.length / 2, and the second at array.length / 2 - 1.
If the array.length is even, your median variable should use the getMean function to calculate the mean of the two middle numbers. Your first argument should be the value of sorted at array.length / 2, and the second at array.length / 2 - 1. If the array.length is odd, your median variable should assign the middle number to the median variable. The middle number is the value of sorted at Math.floor(array.length / 2)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
Challenge Information:
Learn Advanced Array Methods by Building a Statistics Calculator - Step 22
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.