Method: Babbage::Array.percentile
- Defined in:
- lib/babbage/array.rb
.percentile(array, target) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/babbage/array.rb', line 25 def self.percentile(array, target) target = target.to_f / 100.0 index = (array.length - 1) * target sorted_array = array.sort if index == index.to_i sorted_array[index.to_i] else average( sorted_array[index.floor, 2] ) end end |