Created
May 16, 2016 22:57
-
-
Save saneshark/5f04058a4272eca7ca99d4457d5614cb to your computer and use it in GitHub Desktop.
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 array_flattener(array) | |
raise ArgumentError, 'Argument must an array' unless array.is_a? Array | |
flattened_array = [] | |
array.each do |element| | |
if element.is_a? Array | |
flattened_array += array_flattener(element) | |
else | |
flattened_array << element | |
end | |
end | |
flattened_array | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment