logo CodeStepByStep logo

findMedian

Language/Type: JavaScript arrays tallying

Write a function named findMedian that accepts an array of integers as a parameter and returns the median of the numbers in the array. The median is the number that will appear in the middle if you arrange the elements in order. Assume that the array is of odd size (so that one sole element constitutes the median), only contains number elements, and that the values in the array are between 0 and 99 inclusive.

For example, the median of [5, 2, 4, 17, 55, 4, 3, 26, 18, 2, 17] is 5, and the median of [42, 37, 1, 97, 1, 2, 7, 42, 3, 25, 89, 15, 10, 29, 27] is 25.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.