Post History
Article
code-golf
#1: Initial revision
Merge arrays and preserve positions
Given $ n $ lists of numbers: $$ [A_1, A_2, ..., A_x ] $$ $$ [B_1, B_2, ..., B_y ] $$ $$ [C_1, C_2, ..., C_z ] $$ Join them in a way that the index of each element is preserved. The order between elements with the same index does not matter. Sorted: $$ [A_1, B_1, C_1, ..., A_x, B_y, C_z] $$ Arbitrary, but still correct as the rough order is preserved: $$ [A_1, C_1, B_1, C_2, A_2, B_2 ..., B_y, A_x, C_z] $$ If the arrays are of different lengths, extra elements are not inserted, they are merged as-is: $$ [A_1, A_2, A_3, A_4, A_5] $$ $$ [B_1, B_2, B_3] $$ becomes: $$ [A_1, B_1, A_2, B_2, A_3, B_3, A_4, A_5] $$ # Examples These examples assume ordering remains correct. ``` [1, 2, 3], [4, 5, 6] -> [1, 4, 2, 5, 3, 6] [1, 2], [3, 4], [5, 6], [7, 8] -> [1, 3, 5, 7, 2, 4, 6, 8] [1, 2, 3], [4, 5], [6] -> [1, 4, 6, 2, 5, 3] ```