Skip to content

Instantly share code, notes, and snippets.

@drKreso
Created October 24, 2016 20:40
Show Gist options
  • Select an option

  • Save drKreso/a8af2f4350487da0c6ebde4ff0e61e3c to your computer and use it in GitHub Desktop.

Select an option

Save drKreso/a8af2f4350487da0c6ebde4ff0e61e3c to your computer and use it in GitHub Desktop.
Make array flat
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