Created
December 5, 2015 01:29
-
-
Save weilandia/f628f83287a5be1fb592 to your computer and use it in GitHub Desktop.
.Flatten Marquez and the Illusion of Magic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatten_marquez(quote_array) | |
index = 0 | |
while index <= quote_array.length | |
quote_piece = quote_array[index] | |
if quote_piece.kind_of?(Array) | |
if quote_piece.empty? | |
quote_array.delete_at index | |
else | |
inner_quote_piece = quote_piece.shift | |
quote_array.insert index, inner_quote_piece | |
end | |
else | |
index += 1 | |
end | |
end | |
quote_array | |
end | |
buendia = ["Many years later,",["as he faced", "the firing squad,",["Colonel Aureliano Buendía","was to remember","that distant afternoon"],"when his father","took him to"],"discover ice..."] | |
flatten_marquez(buendia) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment