Last active
October 24, 2016 20:40
-
-
Save drKreso/c94ac33a17976134a5efa9b0224a87fd to your computer and use it in GitHub Desktop.
Flat array method
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
| ```ruby | |
| def make_flat(array, result = []) | |
| array.each do |item| | |
| item.class == Array ? make_flat(item, result) : result << item | |
| end | |
| result | |
| end | |
| puts make_flat([[1,2,[3]],4,[[4,6]]]) == [1,2,3,4,4,6] | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment