Last active
December 11, 2015 14:58
-
-
Save chrismo/4618003 to your computer and use it in GitHub Desktop.
loop_zip
This file contains 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 'minitest/autorun' | |
def loop_zip(a, b) | |
b = b * ((a.length / b.length) + 1) if a.length > b.length | |
a.zip(b) | |
end | |
class TestLoopZip < MiniTest::Unit::TestCase | |
def test_2_and_3 | |
assert_equal [['a', 1], ['b', 2]], loop_zip(%w(a b), [1, 2, 3]) | |
end | |
def test_3_and_2 | |
assert_equal [['a', 1], ['b', 2], ['c', 1]], loop_zip(%w(a b c), [1, 2]) | |
end | |
def test_10_and_3 | |
assert_equal [['a', 1], ['b', 2], ['c', 3], | |
['d', 1], ['e', 2], ['f', 3], | |
['g', 1], ['h', 2], ['i', 3], | |
['j', 1]], loop_zip(%w(a b c d e f g h i j), [1, 2, 3]) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment