Created
February 18, 2017 22:39
-
-
Save zoltankiss/41715dad2f3ac6e3017b319fc9829e0a 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(lst) | |
| flattened_lst = [] | |
| lst.each do |e| | |
| if e.is_a?(Array) | |
| flattened_lst += flatten(e) | |
| else | |
| flattened_lst << e | |
| end | |
| end | |
| flattened_lst | |
| end | |
| puts flatten([[ 1, 2, [3]], 4]).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment