5 kyu

Interleaving Arrays

1,158 of 2,158arlaneenalra

Description:

Create a function, that accepts an arbitrary number of arrays and returns a single array generated by alternately appending elements from the passed in arguments. If one of them is shorter than the others, the result should be padded with empty elements.

Examples:

Kata.interleave([1, 2, 3], ["c", "d", "e"]) == [1, "c", 2, "d", 3, "e"]
Kata.interleave([1, 2, 3], [4, 5]) == [1, 4, 2, 5, 3, null]
Kata.interleave([1, 2, 3], [4, 5, 6], [7, 8, 9]) == [1, 4, 7, 2, 5, 8, 3, 6, 9]
Kata.interleave([]) == []
interleave([1, 2, 3], ["c", "d", "e"]) === [1, "c", 2, "d", 3, "e"]
interleave([1, 2, 3], [4, 5]) === [1, 4, 2, 5, 3, null]
interleave([1, 2, 3], [4, 5, 6], [7, 8, 9]) === [1, 4, 7, 2, 5, 8, 3, 6, 9]
interleave([]) === []
interleave([1, 2, 3], ["c", "d", "e"]) == [1, "c", 2, "d", 3, "e"]
interleave([1, 2, 3], [4, 5]) == [1, 4, 2, 5, 3, None]
interleave([1, 2, 3], [4, 5, 6], [7, 8, 9]) == [1, 4, 7, 2, 5, 8, 3, 6, 9]
interleave([]) == []
interleave([1, 2, 3], ["c", "d", "e"]) == [1, "c", 2, "d", 3, "e"]
interleave([1, 2, 3], [4, 5]) == [1, 4, 2, 5, 3, nil]
interleave([1, 2, 3], [4, 5, 6], [7, 8, 9]) == [1, 4, 7, 2, 5, 8, 3, 6, 9]
interleave([]) == []
Algorithms
Arrays

More By Author:

Check out these other kata created by arlaneenalra

Stats:

CreatedSep 21, 2013
PublishedSep 21, 2013
Warriors Trained3795
Total Skips300
Total Code Submissions14628
Total Times Completed2158
JavaScript Completions1158
Python Completions899
Ruby Completions105
Groovy Completions53
Total Stars66
% of votes with a positive feedback rating92% of 420
Total "Very Satisfied" Votes359
Total "Somewhat Satisfied" Votes54
Total "Not Satisfied" Votes7
Ad
Contributors
  • arlaneenalra Avatar
  • jhoffner Avatar
  • GiacomoSorbi Avatar
  • suic Avatar
  • FArekkusu Avatar
  • Glyxerine Avatar
  • user8436785 Avatar
  • Just4FunCoder Avatar
Ad