Created
August 20, 2018 05:48
-
-
Save dbhalling/14228b4db59dc9f58d3916ed1a1fe0a6 to your computer and use it in GitHub Desktop.
Flatten array
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
#Citrus | |
a = [[1,2,[3]],4] | |
aflat = [] | |
def flatten(a) | |
astring = a.to_s | |
test = astring.delete "[" | |
test2 = test.delete "]" | |
# I should be able to combine these two delete statements according to the Ruby docs, but it does not work for me, which would | |
# eliminate a dummy variable. | |
# I should also be able to string together some of th | |
aflatstring = test2.split(',') | |
aflat = aflatstring.map{|x| x.to_i} | |
return aflat | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment