Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def arrayMedian(sequence)
- sequence = sequence.sort
- if sequence.length % 2 == 0 then
- sum = sequence[sequence.length / 2 - 1] + sequence[sequence.length / 2]
- average = sum / 2.to_f
- return average
- end
- if sequence.length % 2 != 0 then
- return sequence[sequence.length / 2]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment