Skip to content

Instantly share code, notes, and snippets.

@MFQ
Created November 24, 2016 19:15
Show Gist options
  • Save MFQ/954f5240430914059f77a59bc0aaa393 to your computer and use it in GitHub Desktop.
Save MFQ/954f5240430914059f77a59bc0aaa393 to your computer and use it in GitHub Desktop.
def flattern(array, main_array, index)
while( index < array.length)
if(array[index].class == Array)
flattern(array[index], main_array, 0)
else
main_array.push(array[index])
end
index = index + 1
end
main_array
end
ar = [1,2,3,[1,2,3,4],45,6,[1,2]]
puts flattern(ar, [], 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment