Skip to content

Instantly share code, notes, and snippets.

@chrismo
Last active December 11, 2015 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismo/4618003 to your computer and use it in GitHub Desktop.
Save chrismo/4618003 to your computer and use it in GitHub Desktop.
loop_zip
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