Skip to content

Instantly share code, notes, and snippets.

@zernie
Created December 8, 2017 13:40
Show Gist options
  • Save zernie/a48ce87badea8cdad73b85a285fd5b20 to your computer and use it in GitHub Desktop.
Save zernie/a48ce87badea8cdad73b85a285fd5b20 to your computer and use it in GitHub Desktop.
def flatten(array)
array.reduce([]) do |sum, n|
sum + (n.kind_of?(Array) ? flatten(n) :[n])
end
end
p flatten([[1,2,[3]],4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment