Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Created May 8, 2015 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilleiguaran/fe8d603081e4e7e6e51e to your computer and use it in GitHub Desktop.
Save guilleiguaran/fe8d603081e4e7e6e51e to your computer and use it in GitHub Desktop.
def average_age
return 0 if @group.empty?
sum = @group.map{|x| x.age}
.reduce(0.0){|sum, x| sum + x}
sum / @group.size
end
def average_age(group)
return 0 if group.empty?
sum = group.map{|x| x.age}
.reduce(0.0){|sum, x| sum + x}
sum / group.size
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment