Write a function mergeArrays(a, b) that returns a new array with all elements of a and then all elements of b.
a and b are arrays of numbers and strings (one array can have both). Each one can have any length, also 0.a in their order, then the elements of b in their order.a or b is empty. Do not return a or b itself.a or b.The interviewer asked for exactly one for loop. The tests check only the result; keep to the rule yourself. One loop over the indexes from 0 to a.length + b.length - 1 is enough.
mergeArrays([1, 2, 3], [4, 5])Returns [ 1, 2, 3, 4, 5 ]
mergeArrays([], ['x'])Returns [ 'x' ]
Asked at Mastercard · Source
mergeArrays([ 1, 2, 3 ], [ 4, 5 ])[ 1, 2, 3, 4, 5 ]mergeArrays([], [ 'x' ])[ 'x' ]Hidden tests run on Submit.