Skip to content

Instantly share code, notes, and snippets.

@ir-norn
Created September 27, 2015 14:37
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 ir-norn/0ccac5f597c0eef63acf to your computer and use it in GitHub Desktop.
Save ir-norn/0ccac5f597c0eef63acf to your computer and use it in GitHub Desktop.
nums = [1,2,3,4,5,1,2,2,3]
p nums.itself { |s| s.inject(:+) / s.size.to_f } # => 2.5555555555555554
p nums.inject(:+) / nums.size.to_f # => 2.5555555555555554
p nums.group_by(&:itself) # => {1=>[1, 1], 2=>[2, 2, 2], 3=>[3, 3], 4=>[4], 5=>[5]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment