Skip to content

Instantly share code, notes, and snippets.

@bayendor
Last active Aug 29, 2015
Embed
What would you like to do?
Flatten an array in ruby without using `flatten`
def flatten_clone(array, level = -1, result = [])
array.each do |element|
if element.is_a?(Array) && level != 0
flatten_clone element, level - 1, result
else
result << element
end
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment