Created
November 15, 2012 05:36
-
-
Save tvladeck/4076830 to your computer and use it in GitHub Desktop.
converting to annual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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