Skip to content

Commit dbc0ef2

Browse files
committed
Create: 1768 Merge Strings Alternately - TypeScript & JavaScript
1 parent 6dc5da1 commit dbc0ef2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var mergeAlternately = function (word1, word2) {
2+
let res = '';
3+
4+
for (let i = 0; i < word1.length || i < word2.length; i++) {
5+
if (i < word1.length) res += word1[i];
6+
if (i < word2.length) res += word2[i];
7+
}
8+
9+
return res;
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function mergeAlternately(word1: string, word2: string): string {
2+
let res = '';
3+
4+
for (let i = 0; i < word1.length || i < word2.length; i++) {
5+
if (i < word1.length) res += word1[i];
6+
if (i < word2.length) res += word2[i];
7+
}
8+
9+
return res;
10+
}

0 commit comments

Comments
 (0)