Skip to content

Instantly share code, notes, and snippets.

@banister
Created December 20, 2014 20:12
Show Gist options
  • Save banister/e989f51e5b64eb1c205a to your computer and use it in GitHub Desktop.
Save banister/e989f51e5b64eb1c205a to your computer and use it in GitHub Desktop.
[5] pry(main)> def thing(array)
[5] pry(main)* if array.size == 0
[5] pry(main)* []
[5] pry(main)* else
[5] pry(main)* thing(array[0..-2]) + [array.inject(:+)]
[5] pry(main)* end
[5] pry(main)* end
=> :thing
[6] pry(main)> thing([1, 2, 3, 4])
=> [1, 3, 6, 10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment