Chloe is practicing JavaScript, she got a challenge to write a JavaScript Function getMiddleValue()
which has a parameter arr
should accept an array of numbers and sort the array and return the middle value of the array if length of the array is odd and average of the middle values if the length of the array is even.
She has written her code (which is shared with you in the index.js
file), but there seems to a bug which she is unable to figure out. The function doesn't not return the middle number of the array having odd length. Can you help her debug this?
A sample array values are already provided to you to aid you in debugging this. Once you've fixed the bug, run the tests to verify if the bug has been fixed. You have to try to change the as minimal as possible and completely avoid re-writing the code.
All the best!