Here's a code snippet that calculates the standard deviation of all elements in an array in Ruby, by first calculating the mean of the array and then summing the squared difference of each element from the mean:
main.rb148 chars7 lines
To use this method, simply pass in your array as an argument:
main.rb61 chars3 lines
This will output 1.5811388300841898
, which is the standard deviation of the array.
gistlibby LogSnag