Implement Array#flatten

Submitted By:
david

Difficulty:
Medium

Tags:
arrays

Instructions:
Implement Array#flatten.

Hidden Code:
There is hidden code with assertions that is also being run to test out your code.

Code:
class Array
  def flatten
    ___
  end
end

assert_equal [1, 2, [[{a: :b}]]].flatten, [1, 2, {:a => :b}]
assert_equal [1, [2, 3, [4, 5, [6, 7]]], 8].flatten, [1, 2, 3, 4, 5, 6, 7, 8]
assert_equal [].flatten, []
assert_equal [[1, 2], [3, 4]].flatten, [1, 2, 3, 4]

Your Solution

Ruby 1.9.3

Back to Problems