I’m stack here for months, cant seems to go through please assist
Please share a link to the challenge and your code
thank you, now please share your code
const getMedian = (array) => {
const sorted = array.sort((a, b) => a - b);
return !(array.length % 2) ? getMean([sorted[sorted.length / 2 - 1], sorted[sorted.length / 2]])
: sorted[Math.floor(sorted.length / 2)]
are there more places in there where you can use the sorted array?
yes, I think so. but I think I’ve added to many spaces
const getMedian = (array) => {
const sorted = array.sort((a, b) => a - b);
return !(array.length % 2) ? getMean([sorted[sorted.length / 2 - 1], sorted[sorted.length / 2]])
: sorted[Math.floor(sorted.length / 2)]
are you sure there isn’t one more place in which you can substitute sorted in?
is there any reason to use array again after the first line?
I’ll have to check, and run the code again, but I’ve stack here for months
Review this instruction:
check if the length of
sortedis even.
Are you doing this?
