Skip to content

Instantly share code, notes, and snippets.

@Zkuns
Last active September 8, 2015 14:48
Show Gist options
  • Save Zkuns/743af19d525e7cb32cf5 to your computer and use it in GitHub Desktop.
Save Zkuns/743af19d525e7cb32cf5 to your computer and use it in GitHub Desktop.
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