Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions lib/transport.rb

This file was deleted.

4 changes: 4 additions & 0 deletions lib/transpose.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def transpose(source)
matrix = source.split("\n").map {|s| s.split(" ")}
matrix.transpose.map {|s| s.join(" ")}.join("\n")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

プレーンテキストから、行列への変換(その逆の変換)部分は他のメソッドで使用することがあれば、そのタイミングでメソッド化すればいいと思うので、今はこのままで問題ないと思います!

end
14 changes: 0 additions & 14 deletions test/transport_test.rb

This file was deleted.

16 changes: 16 additions & 0 deletions test/transpose_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'minitest/autorun'
require './lib/transpose'

class TransposeTest < MiniTest::Test
def test_transpose_3x3
input = "1 2 3\n4 5 6\n7 8 9"
output = "1 4 7\n2 5 8\n3 6 9"
assert_equal output, transpose(input)
end

def test_transpose_3x4
input = "1 2 3\n4 5 6\n7 8 9\n10 11 12"
output = "1 4 7 10\n2 5 8 11\n3 6 9 12"
assert_equal output, transpose(input)
end
end