Skip to content

Instantly share code, notes, and snippets.

@ckazu
Created February 4, 2016 02:54
Show Gist options
  • Save ckazu/b0dc7f4a1d77b9f74610 to your computer and use it in GitHub Desktop.
Save ckazu/b0dc7f4a1d77b9f74610 to your computer and use it in GitHub Desktop.
sort_lists.rb
def sort_lists(a, b)
list = (a + b).sort
[list[0...a.size], list[a.size..-1]]
end
require 'minitest/autorun'
class TestSortLists < Minitest::Test
def test_sort_lists
data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'].shuffle
assert_equal([['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h']], sort_lists(data[0..3], data[4..7]))
end
def test_sort_differ_size_lists
data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'].shuffle
assert_equal([['a', 'b'], ['c', 'd', 'e', 'f', 'g', 'h']], sort_lists(data[0..1], data[2..7]))
end
end
@ckazu
Copy link
Author

ckazu commented Feb 4, 2016

Kazuyuki Chinda [珍田] a.k.a. @ckazu [10:38]

  list = (a + b).sort
  list.each_slice(list.size / 2).to_a

配列の数気にしないならこうかな

Kazuyuki Chinda [珍田] a.k.a. @ckazu [10:43]
違うな.テストは通るけど,多分このメソッドは最初に渡された引数のサイズそのままでソートしろってことなんだな

[10:47]

という経緯あった.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment