Skip to content

Instantly share code, notes, and snippets.

@alvarezgarcia
Created April 30, 2019 23:17
Show Gist options
  • Save alvarezgarcia/c6b76fcb015e18c1543a26364b6d5e17 to your computer and use it in GitHub Desktop.
Save alvarezgarcia/c6b76fcb015e18c1543a26364b6d5e17 to your computer and use it in GitHub Desktop.
const firstList = [1, 2, 3, 5, 9, 10, 13, 16, 28];
const secondList = [5, 6, 7, 8, 11, 42, 11];
const maxLength = firstList.length > secondList.length ? firstList.length : secondList.length;
let finalList = [];
for (let k = 0; k < maxLength; k++) {
if (!firstList[k]) {
finalList.push(secondList[k]);
} else if (!secondList[k]) {
finalList.push(firstList[k]);
} else {
finalList.push(firstList[k], secondList[k]);
}
}
console.log(finalList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment