The flatten
method on Array
squishes any nested
arrays into the outer array like this:
> [[1,2],[3,[4,5]]].flatten
=> [1, 2, 3, 4, 5]
Implement a CustomArray
class that works like this:
> c = CustomArray.new([[1,2],[3,[4,5]]])
> c.flatten
=> [1, 2, 3, 4, 5]
> d = CustomArray.new([[12,2],[3,[4,5]]])
> d.flatten
=> [12, 2, 3, 4, 5]
But the CustomArray
class may not use the
built-in .flatten
method.