Skip to content

Instantly share code, notes, and snippets.

@weilandia
Created December 5, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weilandia/f628f83287a5be1fb592 to your computer and use it in GitHub Desktop.
Save weilandia/f628f83287a5be1fb592 to your computer and use it in GitHub Desktop.
.Flatten Marquez and the Illusion of Magic
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