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 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 |