Skip to content

Instantly share code, notes, and snippets.

@gentilfp
Created February 6, 2018 01:04
Show Gist options
  • Save gentilfp/20c9a2f66d49977e016b3adcc769bc12 to your computer and use it in GitHub Desktop.
Save gentilfp/20c9a2f66d49977e016b3adcc769bc12 to your computer and use it in GitHub Desktop.
Recursive Custom Array Flatter
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