Skip to content

Instantly share code, notes, and snippets.

@mediter
Created October 19, 2018 02:39
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 mediter/0bbd44c2955c60cfa515744cbfa0ac9c to your computer and use it in GitHub Desktop.
Save mediter/0bbd44c2955c60cfa515744cbfa0ac9c to your computer and use it in GitHub Desktop.
[Ruby Array Sum] #ruby #iterator #sum
# you can call #sum iterator on it:
numbers = [1, 2, 3, 4, 5]
numbers.sum
# => 15
# N.B: In Ruby versions < 2.4, sum didn't exist. The idiomatic way to get the same result was with #reduce:
numbers.reduce(:+)
# => 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment