Last active
February 16, 2018 19:54
-
-
Save jeann2013/4e9752945012242fcae1b0f1e2f8324a to your computer and use it in GitHub Desktop.
flatten_arrays
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
a=[[[1,2,[3]],4]=>[1,2,3,4]] | |
def flattJean(arr) | |
arr.each_with_object([]) do |element, flattened| | |
flattened.push *(element.is_a?(Array) ? flattJean(element) : element) | |
end | |
end | |
puts flattJean(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment