Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using flat_map to flatten a nested array
flat = (l = ->(x) { x.flat_map {|e| Array === e ? l.(e) : e } })
flat.([1, 2, 3, [4, 5, [6], [ ] ] ])
#==> [1,2,3,4,5,6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.