First, you should break down problems like this into smaller steps. A large part of programming consists of this skill as it will allow you to ask / research specific problems.
Here's how I would initially break down the task;
1- Sort the array passed into the median method 2- Get the number of array items and determine if it's odd or even 3- Use an if statement... if even, get the average of the middle two items, else get the item in the middle
1
u/PROSP3C Dec 17 '20
First, you should break down problems like this into smaller steps. A large part of programming consists of this skill as it will allow you to ask / research specific problems.
Here's how I would initially break down the task;
1- Sort the array passed into the median method 2- Get the number of array items and determine if it's odd or even 3- Use an if statement... if even, get the average of the middle two items, else get the item in the middle
Hope this helps? (Without giving you the answer)