Skip to content

Instantly share code, notes, and snippets.

@jeann2013
Last active February 16, 2018 19:54
Show Gist options
  • Save jeann2013/4e9752945012242fcae1b0f1e2f8324a to your computer and use it in GitHub Desktop.
Save jeann2013/4e9752945012242fcae1b0f1e2f8324a to your computer and use it in GitHub Desktop.
flatten_arrays
a=[[[1,2,[3]],4]=>[1,2,3,4]]
def flattJean(arr)
arr.each_with_object([]) do |element, flattened|
flattened.push *(element.is_a?(Array) ? flattJean(element) : element)
end
end
puts flattJean(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment