Created
February 20, 2018 03:10
-
-
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
This file contains hidden or 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 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