Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'awesome_print'
- class Array
- def flatten_2
- reduce([]) do |acc, sub_a|
- if sub_a.is_a?(Array)
- acc + sub_a.flatten_2
- else
- acc << sub_a
- end
- end
- end
- end
- a = [1, 2, [3, 4, [5, 6, [], 7], [8, 9]], 10, 11]
- ap a.flatten == a.flatten_2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement