Skip to main content

1768.js

/** ------------------------------------------------------------------------------
*
* 2023-04-18
* 1768. Merge String
* 릿코드 링크
*
------------------------------------------------------------------------------ */
/**
* @param {string} word1
* @param {string} word2
* @return {string}
*/
var mergeAlternately = function (word1, word2) {
let answer = "";

let n = Math.max(word1.length, word2.length);

for (let i = 0; i < n; i++) {
if (word1[i]) {
answer += word1[i];
}
if (word2[i]) {
answer += word2[i];
}
}

return answer;
};

console.log();