def median(array) sorted = array.sort len = sorted.length return (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0 end
I understand everything up to the return statement. Can some describe to me how the return statement plays out with an array = [1, 2, 3, 4, 5]. For example, with an array length of 5 I don't understand how the second half of the numerator of the return statement works. What does it mean to have sorted[5/2] ------ I interpret this as accessing the 2.5th element in the sorted array. I'm confused. Thank you for your assistance!
This post has been edited by xclite: 16 December 2013 - 01:41 PM
Reason for edit:: Adding code tags.