Skip to content

Instantly share code, notes, and snippets.

View hernamvel's full-sized avatar
🏠
Working from home

Hernan Velasquez hernamvel

🏠
Working from home
View GitHub Profile
def flatten(integer_array)
result = []
integer_array.each do |i|
if i.is_a? Array
# It's and array. Go a recursevely flatten this child element
child_array = flatten i
result.concat child_array
else
# It's an integer. Just added to the final array
result << i