Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Ruby :: how to generate a controller in rails 
Ruby :: ruby test is number 
Ruby :: how to make a new array ruby 
Ruby :: how to add to an array ruby 
Ruby :: ruby downcase 
Ruby :: ruby array prepend vs unshift 
Ruby :: array to hash ruby 
Ruby :: call a class method ruby 
Ruby :: iterate over array ruby 
Ruby :: Rails validations: unique scope 
Ruby :: ruby rails where not in 
Ruby :: ruby create array 
Ruby :: rails column datetime 
Ruby :: rails always 2 decimal 
Ruby :: validations rails integer suprior to 0 
Ruby :: ruby generate task 
Ruby :: including libraries in ruby 
Ruby :: rails array pop first n elements 
Ruby :: ruby in array 
Ruby :: rails start id to 1000 
Ruby :: Validate French phone numbers 
Ruby :: render to string rails 
Ruby :: ruby regex replace capture group 
Ruby :: set db environment to development 
Ruby :: ruby file copy 
Ruby :: rails list down attributes of model 
R :: r delete all variables 
R :: how to add new value in R list 
R :: r replace blank string with na 
R :: Extract number from string field R 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =