Hey I got an array “a” which looks like this:
[[5], [7], [8]] # result of "puts a.to_s"
How can I calculate the average of the array.
I already have a method that works for normal arrays with one dimension:
def average
return self.reduce(:+)/self.length.to_f
end
How can I convert the array from above in a normal array or how to use that method for the more dimensional array?
Using
Array#flattenyou can use your predefined average method.