Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

ruby median find

def median(array)
  return nil if array.empty?
  
  sorted = array.sort
  len = sorted.length 
  (sorted[(len - 1) / 2] + sorted[len / 2]) / 2
end
 
PREVIOUS NEXT
Tagged: #ruby #median #find
ADD COMMENT
Topic
Name
1+9 =