Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def flatten(array)
- out = []
- array.each do |el|
- if el.is_a?(Array)
- out.concat(flatten(el))
- else
- out.push(el)
- end
- end
- out
- end
- p flatten([[1,2,[3]], 4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement