Merging Strings With Merge Alternately Functionality
Merge two strings by alternating characters: `mergeAlternately` function takes two strings, iterates through each character, and returns a new string with chars from both inputs.
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('') };