Merge Strings Alternately ( Javascript )

131


var mergeAlternately = function(word1, word2) {
let word3 = [];

if(word1.length-1>word2.length-1)
for (let i=0; i<word1.length; i++){

word3.push(word1[i]);
if(word2[i] != undefined) word3.push(word2[i]);
}
else
for (let i=0; i<word2.length; i++){
if(word1[i] != undefined) word3.push(word1[i]);
word3.push(word2[i]);
}

const mergedString = word3.join('');

return mergedString
};