Five programming problems every Software Engineer should be able to solve in less than 1 hour

Geoff Canyon gcanyon at gmail.com
Sat May 9 19:28:31 EDT 2015


Problem 2

Write a function that combines two lists by alternatingly taking elements.
For example: given the two lists [a, b, c] and [1, 2, 3], the function
should return [a, 1, b, 2, c, 3].



function interleave X,Y
   split X using comma
   split Y using comma
   repeat with i = 1 to max(item 2 of the extents of X,item 2 of the
extents of Y)
      put X[i],Y[i],"" after R
   end repeat
   return char 1 to -2 of R
end interleave


Test Data (taken in pairs of lines)
1,2,3
a,b,c

1,2,3
a,b,c,d
1,2,3

Test Output
1,a,2,b,3,c
,1,,2,,3
a,1,b,2,c,3,d,



More information about the use-livecode mailing list