Calculate the nth percentile of an array using linear interpolation.
Code
Generalsorted = arr.sort
index = (p / 100.0) * (sorted.length - 1)
lower = index.floor
fraction = index - lower
result = sorted[lower] + fraction * ((sorted[lower + 1] || sorted[lower]) - sorted[lower])
return resultParameters
Array of numbers
Percentile (0-100)
Server
More Ruby Snippets
Binary to Decimal
Convert a binary string representation to its decimal number equivalent.
Bytes to Human Readable
Convert bytes to human readable format (KB, MB, GB, etc.) for file sizes.
Calculate Median
Calculate the median value of an array of numbers.
Calculate Mode
Find the most frequent value(s) in an array.
Celsius to Fahrenheit
Convert temperature from Celsius to Fahrenheit using the standard formula.
Clamp Number
Restrict a number to be within a minimum and maximum range.