Skip to content

Instantly share code, notes, and snippets.

@dubistdu
Created November 21, 2019 13:47
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 dubistdu/f02f87cc2c344008173e3b47d560a13e to your computer and use it in GitHub Desktop.
Save dubistdu/f02f87cc2c344008173e3b47d560a13e to your computer and use it in GitHub Desktop.
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