Tuck in Array

Published by Mubashir Hassan in

Create a function that takes two arrays and insert the second array in the middle of the first array.

Examples

tuck_in([1, 10], [2, 3, 4, 5, 6, 7, 8, 9]) ➞ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

tuck_in([15,150], [45, 75, 35]) ➞ [15, 45, 75, 35, 150]

tuck_in([[1, 2], [5, 6]], [[3, 4]]) ➞ [[1, 2], [3, 4], [5, 6]]

Notes

The first array always has two elements.

Watch a quick demo on how Edabit works.