Last active
September 8, 2015 14:48
-
-
Save Zkuns/743af19d525e7cb32cf5 to your computer and use it in GitHub Desktop.
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
def parse_array array, result=[] | |
return result if array == [] | |
obj = array.shift | |
if obj.is_a?(Array) | |
obj = parse_array obj | |
parse_array array, result + obj | |
else | |
parse_array array, result << obj | |
end | |
end | |
require 'minitest/autorun' | |
describe '#parse_array' do | |
it "will parse the array" do | |
parse_array([1,[2,3],[4,5,[6,7]]]).must_equal [1, 2, 3, 4, 5, 6, 7] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment