Heres , the solution try to understand the code š
/**
* @param {string} word1
* @param {string} word2
* @return {string}
*/
var mergeAlternately = function(word1, word2) {
const res = [];//final result array
//looping sufficient for every char in both words
for(let i = 0 ;i < word1.length + word2.length ;i++){
//pushing chars in word1
if(i<word1.length){
res.push(word1[i])
}
//pushing chars in word1
if(i<word2.length){
res.push(word2[i])
}
}
return res.join('')
};
Top comments (1)
Please do follow the channel , will be updating more solutions and patterns