Appearance
1768. 交替合并字符串
题解代码
javascript
/**
* @param {string} word1
* @param {string} word2
* @return {string}
*/
var mergeAlternately = function (word1, word2) {
let res = '',
i = 0,
j = 0;
for (; i < word1.length && j < word2.length; i++, j++) {
res += word1[i] + word2[j];
}
if (i === word1.length) {
res += word2.slice(j);
} else {
res += word1.slice(i);
}
return res;
};