ruby - How to calculate median in a Rails app that uses SQLite3? -
is there way median calc in rails 4 app uses default sqlite3 database?
i've built app add median function, , see active_median gem works postgresql now:
try calculate median
def median(array) sorted = array.sort len = sorted.length return (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0 end
Comments
Post a Comment