Created
November 21, 2019 13:47
-
-
Save dubistdu/f02f87cc2c344008173e3b47d560a13e to your computer and use it in GitHub Desktop.
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
def split_and_add(arr, n) | |
n.times { arr.length.odd? ? arr.unshift(0) : arr | |
arr = arr.each_slice(arr.length/2).to_a.transpose.map { |x| x.sum } | |
} | |
arr | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment