Skip to content

Instantly share code, notes, and snippets.

@dbhalling
Created August 20, 2018 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbhalling/14228b4db59dc9f58d3916ed1a1fe0a6 to your computer and use it in GitHub Desktop.
Save dbhalling/14228b4db59dc9f58d3916ed1a1fe0a6 to your computer and use it in GitHub Desktop.
Flatten array
#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