Created
October 3, 2017 10:24
-
-
Save salmanx/cfa945508b55b2f943d40f952dec728b to your computer and use it in GitHub Desktop.
A simple ruby method for array flatten
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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