Skip to content

Instantly share code, notes, and snippets.

@sposmen
Last active August 6, 2019 20:27
Show Gist options
  • Save sposmen/f3f41a1e0c883829929e08dcb0fdc96d to your computer and use it in GitHub Desktop.
Save sposmen/f3f41a1e0c883829929e08dcb0fdc96d to your computer and use it in GitHub Desktop.
Flatten example
data_array = [[1,2,[3]],4]
def manual_flatten(arr)
new_array = []
arr.each do |elm|
if elm.kind_of?(Array)
new_array.concat(manual_flatten(elm))
else
new_array << elm
end
end
new_array
end
p manual_flatten(data_array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment