Skip to content

Instantly share code, notes, and snippets.

@salmanx
Created October 3, 2017 10:24
Show Gist options
  • Save salmanx/cfa945508b55b2f943d40f952dec728b to your computer and use it in GitHub Desktop.
Save salmanx/cfa945508b55b2f943d40f952dec728b to your computer and use it in GitHub Desktop.
A simple ruby method for array flatten
class FlattenArray
def self.flattify(array,init=[])
array.each do |a|
if a.class==Array
flattify(a,init)
else
init << a
end
end
init
end
p flattify([[1,2,[3]],4])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment