Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 511 Bytes

flatten.markdown

File metadata and controls

23 lines (17 loc) · 511 Bytes

Flatten

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]

The object of this exercise is to recreate the functionality of the flatten method that we have in Ruby's Array class.

Implement a CustomArray class that works like this:

> c = CustomArray.new([[1,2],[3,[4,5]]])
> c.flatten
=> [1, 2, 3, 4, 5]

But the CustomArray class may not use the built-in .flatten method or .to_s