Created
September 16, 2016 20:31
-
-
Save mwlang/47057a0333b1a42bdbdbf4391e2a6900 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
2.1.5 :027 > def flatten a | |
2.1.5 :028?> flat = [] | |
2.1.5 :029?> a.each{|i| i.is_a?(Array) ? flat += flatten(i) : flat << i } | |
2.1.5 :030?> return flat | |
2.1.5 :031?> end | |
=> :flatten | |
2.1.5 :032 > flatten [1,2,[:a,:b,:c],3,4] | |
=> [1, 2, :a, :b, :c, 3, 4] | |
2.1.5 :033 > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment