Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sorted = stats[key].sort
min = sorted.first
max = sorted.last
sum = sorted.inject(0) {|sum,sample| sum + sample }
avg = sum / sorted.size
# calculate standard deviation
diffs = sorted.map {|val| val - avg }
squared_diffs = diffs.map {|val| val ** 2 }
sqd_diff_sum = squared_diffs.inject(0) {|sum,sample| sum + sample }
dev = Math.sqrt( sqd_diff_sum / sorted.size )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.