Skip to content

Instantly share code, notes, and snippets.

@AdityaBhutani
Created February 25, 2020 17:15
Show Gist options
  • Save AdityaBhutani/283bdd258952e0387bdc276634b4d80b to your computer and use it in GitHub Desktop.
Save AdityaBhutani/283bdd258952e0387bdc276634b4d80b to your computer and use it in GitHub Desktop.
custom flatten
def custom_flat (arr, res = [])
arr.each_with_index do |ele, i|
if arr[i].class.name == "Array"
#p "ARR - #{arr[i]}"
custom_flat arr[i], res
else
#p "ELE - #{arr[i]}"
res << arr[i]
#p res
end
end
res
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment