Last active
December 5, 2018 03:11
-
-
Save BrianPurgert/de3aa855e8405a26e026855c65620d88 to your computer and use it in GitHub Desktop.
flatten an array of arbitrarily nested arrays of integers into a flat array of integers
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
# flattens arbitrarily nested arrays of integers into a flat array of integers. | |
# | |
# Examples: | |
# | |
# flatten_integer_arrays([[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]) | |
# # [1,2,3,4,5,6,7,8,9,10] | |
# | |
def flatten_integer_arrays(nested) | |
nested.to_s.scan(/\d+/).map(&:to_i) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment