Created
September 5, 2017 06:47
-
-
Save batbayar-su/10cd0ce5c9b8f7ca89258a362a6c1c98 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 flatten(subarr, flat = []) | |
| subarr.each do |item| | |
| if item.class == Array | |
| flatten(item, flat) | |
| else | |
| flat << item | |
| end | |
| end | |
| flat | |
| end | |
| flat_array = flatten([1,2,3,[4,5,[6,7,8],9,10,[11,12,[13,14]]]]) | |
| puts flat_array.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment