Created
July 22, 2016 07:54
-
-
Save sonianand11/898ac4d23fa23af5012e80393b855e7a to your computer and use it in GitHub Desktop.
This file contains 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
@result = [] | |
def flatten_it(array) | |
array.each do |element| | |
element.is_a?(Array) ? flatten_it(element) : @result << element | |
end | |
end | |
flatten_it([[1,2,[3]],4]) | |
puts @result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment