Created
February 6, 2018 01:04
-
-
Save gentilfp/20c9a2f66d49977e016b3adcc769bc12 to your computer and use it in GitHub Desktop.
Recursive Custom Array Flatter
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 recursive_custom_array_flat(elem, flatten_array=[]) | |
return elem if elem.is_a? Integer | |
elem.each do |value| | |
recursive_return = recursive_custom_array_flat(value, flatten_array) | |
flatten_array << recursive_return unless recursive_return.is_a? Array | |
end | |
flatten_array | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment