Skip to content

Instantly share code, notes, and snippets.

@mathamoz
Created May 19, 2016 16:00
Show Gist options
  • Save mathamoz/bb0f240edbc51f1b79c9b5e5591d32ea to your computer and use it in GitHub Desktop.
Save mathamoz/bb0f240edbc51f1b79c9b5e5591d32ea to your computer and use it in GitHub Desktop.
Simple Ruby function to recursively flatten an array and return the result
def flatten_array (arr, result=[])
arr.each do |el|
if el.is_a?(Array)
flatten_array(el, result)
else
result.push(el)
end
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment