Last active
September 23, 2016 12:00
-
-
Save gazeldx/5539e9c96f6781601ca91cdf0e443b9c 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
class SmallTool | |
def initialize | |
@result_array = [] | |
end | |
def array_flatten(target_array) | |
target_array.each do |item| | |
if item.is_a?(Array) | |
array_flatten(item) | |
else | |
@result_array << item | |
end | |
end | |
@result_array | |
end | |
end | |
# puts "#{SmallTool.new.array_flatten([[1, 2, [3]], 4])}" |
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
require 'test/unit' | |
require_relative 'flatten' | |
class TestFlatten < Test::Unit::TestCase | |
def setup | |
@small_tool = SmallTool.new | |
end | |
def test_flatten | |
assert_equal([1, 2, 3, 4], @small_tool.array_flatten([[1, 2, [3]], 4])) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment