Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- send_to = -> (arr, target) { arr.map { |v| target << v } }
- def flatten_this(array, lambda)
- raise NoMethodError unless array.is_a?(Array)
- result = []
- array.each do |element|
- element.is_a?(Array) ? lambda.call(element, result) : result << element
- end
- result
- end
- flatten_this([1, 2, 3, [4, 5, [6], [ ] ] ], send_to)
Add Comment
Please, Sign In to add comment