6 kyu

Alternating Loops

557 of 1,454joh_pot

Description:

Write

function combine()
def combine()
def combine()
combine :: [[a]] -> [a]

that combines arrays by alternatingly taking elements passed to it.

E.g

combine(['a', 'b', 'c'], [1, 2, 3]) == ['a', 1, 'b', 2, 'c', 3]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5]) == ['a', 1, 'b', 2, 'c', 3, 4, 5]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5], [6, 7], [8]) == ['a', 1, 6, 8, 'b', 2, 7, 'c', 3, 4, 5]
combine(['a', 'b', 'c'], [1, 2, 3]) == ['a', 1, 'b', 2, 'c', 3]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5]) == ['a', 1, 'b', 2, 'c', 3, 4, 5]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5], [6, 7], [8]) == ['a', 1, 6, 8, 'b', 2, 7, 'c', 3, 4, 5]
combine(['a', 'b', 'c'], [1, 2, 3]) == ['a', 1, 'b', 2, 'c', 3]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5]) == ['a', 1, 'b', 2, 'c', 3, 4, 5]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5], [6, 7], [8]) == ['a', 1, 6, 8, 'b', 2, 7, 'c', 3, 4, 5]
combine [[1, 2, 3], [1, 2, 3]]                    == [1, 1, 2, 2, 3, 3]
combine [[1, 2, 3], [1, 2, 3, 4, 5]]              == [1, 1, 2, 2, 3, 3, 4, 5]
combine [[1, 2, 3], [1, 2, 3, 4, 5], [6, 7], [8]] == [1, 1, 6, 8, 2, 2, 7, 3, 3, 4, 5]

Arrays can have different lengths.

Fundamentals
Algorithms

Stats:

CreatedSep 1, 2015
PublishedSep 1, 2015
Warriors Trained2717
Total Skips116
Total Code Submissions5119
Total Times Completed1454
JavaScript Completions704
Ruby Completions131
Python Completions557
Haskell Completions123
Total Stars71
% of votes with a positive feedback rating95% of 291
Total "Very Satisfied" Votes267
Total "Somewhat Satisfied" Votes21
Total "Not Satisfied" Votes3
Ad
Contributors
  • joh_pot Avatar
  • bkaes Avatar
  • g964 Avatar
  • GiacomoSorbi Avatar
  • JohanWiltink Avatar
  • bidouille Avatar
  • albertogcmr Avatar
  • solitude Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad