Skip to content

Instantly share code, notes, and snippets.

View sgeef's full-sized avatar
🏠
Working from home

Stephan Teeuwen sgeef

🏠
Working from home
View GitHub Profile
@sgeef
sgeef / README.md
Last active July 10, 2019 15:02
Interview assignment 10/07/19 (#flatten)

Interview task made by Stephan Teeuwen

build flatten without using Array#flatten example: [[1,2,[3]],4] to [1,2,3,4]

Testing:

Run following command to test the functioning of the extension method on Array rspec ./flatten_spec.rb --format documentation

Implementation of flatten assignment:

As commented as well in the code, i used the most basic methods i can think of to avoid #each, #flatten and others and make it as plain ruby as possible. Basically what we do is making an recursive loop, to make an infinitly deeply nested array even flattable, it would be the developers responsibility to use this carefully as for sure it's not the optimal way to work with to large array's as this would require memory usage and speed usage testing.