Skip to content

Instantly share code, notes, and snippets.

@tvladeck
Created November 15, 2012 05:36
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 tvladeck/4076830 to your computer and use it in GitHub Desktop.
Save tvladeck/4076830 to your computer and use it in GitHub Desktop.
converting to annual
irb(main):002:0> def convert_to_annual(ary)
irb(main):003:1> len = ary.length
irb(main):004:1> rem = len % 12
irb(main):005:1> idx = len / 12
irb(main):006:1> ret = idx.times.map { |i| ary[i..(i+11)].reduce(:+) }
irb(main):007:1> ret << ary[(len - rem)..(len)].reduce(:+)
irb(main):008:1> ret
irb(main):009:1> end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment