I was given a task that involves working with two arrays filled with random strings in Test.data. The goal is to create a single list containing elements alternating between the two arrays.
For example:
a: ['a', 'b', 'c']
b: ['d', 'e']
-> ['a', 'd', 'b', 'e', 'c']
Despite my best efforts, the code I attempted only replaced the existing data in Test.data.
Test.data = function arry(a, b) {
const c = [];
for (let i = 0; i < Math.max(a.length, b.length); i++) {
if (a[i] != undefined) {
c.push(a[i]);
}
if (b[i] != undefined) {
c.push(b[i]);
}
}
}
I understand that the issue lies in how I am applying the function to the object, but unfortunately, I am unsure of the correct solution at this time.