diff --git a/Easy/1768. Merge Strings Alternately/solution.js b/Easy/1768. Merge Strings Alternately/solution.js new file mode 100644 index 0000000..6400c2b --- /dev/null +++ b/Easy/1768. Merge Strings Alternately/solution.js @@ -0,0 +1,25 @@ +function mergeAlternately(word1, word2) { + // To store the final string + let result = ""; + // For every index in the strings + for (let i = 0; i < word1.length || i < word2.length; i++) { + + // First choose the ith character of the + // first string if it exists + if (i < word1.length) + result += word1.charAt(i); + + // second string if it exists + if (i < word2.length) + result += word2.charAt(i); + + } + + return result; +} + +// Driver code +let word1 = "abc"; +let word2 = "pqr"; +console.log(mergeAlternately(word1, word2)); +//This code is Contributed by chinmaya121221