Created
February 16, 2017 04:50
-
-
Save mrdougwright/4283d01e584f9fca747b616e2874345e to your computer and use it in GitHub Desktop.
Flatten an array of an arbitrary amount of arrays.
This file contains hidden or 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 make_flat(arr, flat_arr=[]) | |
arr.each do |el| | |
el.is_a?(Array) ? make_flat(el, flat_arr) : flat_arr.push(el) | |
end | |
flat_arr | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment