Q:

Interleave two strings of different length

I have two string a and b, length of b is half of length of a, I tried to create a loop to put on character of b every 2 character of a I tried this

let a = "pekaoo";
let b = "eb!";
let stop = a.length;
for (let i = 1; i <= stop; i += 2) {
    a = a.substring(0,i) + b[i/2] + a.substring(i);
}

console.log(a);

which is supposed to show 'peekaboo! but don't work

A:

Using replace()

let a = "pekao";
let b = "eb!";

let arr = [...b]
let res = a.replace(/.{1,2}/g, match => match + arr.shift())

console.log(res);

