Learn Functional Programming by Building a Spreadsheet - Step 24

Tell us what’s happening:

Hi all,

The code below is not passing the tutorial and keeps saying
You should use the return keyword.

Could anyone please give me more hints?

Your code so far

const median = nums => {
    const sorted = nums.slice().sort((a, b) => a - b);
    const length = sorted.length;
    const middle = Math.ceil(length / 2 - 1);
    return isEven(length) ?(sorted[middle] + sorted[middle + 1]) / 2 : sorted[middle];
};

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 24

Hey @twghydc4b01
This is what is missing in your code

you’ll need to round the middle value up.

yup. Math.ceil() was used

Now add it in the last bit of the fuction of your tenary operator here

Remove it here

interesting, after moving the Math.ceil like this sorted[Math.ceil(middle)]
finally another hints other than using return is pop out

If the ternary is truthy, you should call your average() function.

and the code below got pass, many thanks @opudoprince

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.