Created
November 24, 2016 19:15
-
-
Save MFQ/954f5240430914059f77a59bc0aaa393 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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