Last active
August 6, 2019 20:27
-
-
Save sposmen/f3f41a1e0c883829929e08dcb0fdc96d to your computer and use it in GitHub Desktop.
Flatten example
This file contains 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
data_array = [[1,2,[3]],4] | |
def manual_flatten(arr) | |
new_array = [] | |
arr.each do |elm| | |
if elm.kind_of?(Array) | |
new_array.concat(manual_flatten(elm)) | |
else | |
new_array << elm | |
end | |
end | |
new_array | |
end | |
p manual_flatten(data_array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment