Skip to content

Instantly share code, notes, and snippets.

@bdfinlayson
Created February 20, 2018 03:10
Show Gist options
  • Save bdfinlayson/f15d42cf36957f377f0c52c4cd9e59f4 to your computer and use it in GitHub Desktop.
Save bdfinlayson/f15d42cf36957f377f0c52c4cd9e59f4 to your computer and use it in GitHub Desktop.
Flattening an array of arbitrarily nested arrays of integers into a flat array of integers
def to_pancake(ingredients, pancake = [])
ingredients.each do |ingredient|
ingredient.is_a?(Array) ? to_pancake(ingredient, pancake) : pancake << ingredient
end
pancake
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment