Created
September 16, 2016 15:15
-
-
Save Irostovsky/7b894e064970b6a256cf26ef726eb71c to your computer and use it in GitHub Desktop.
flatten
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 flattify(array) | |
array.each_with_object([]) do |element, flattened| | |
flattened.push *(element.is_a?(Array) ? flattify(element) : element) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment