Skip to content

Commit 8a34f43

Browse files
authored
Merge pull request #2 from Amir-16/solve
refactor
2 parents 9125172 + b11316b commit 8a34f43

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Easy/1768. Merge Strings Alternately/solution.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ function mergeAlternately(word1, word2) {
66

77
// First choose the ith character of the
88
// first string if it exists
9-
if (i < word1.length)
9+
if (i < word1.length)
10+
{
1011
result += word1.charAt(i);
11-
12-
// second string if it exists
13-
if (i < word2.length)
12+
13+
}
14+
if (i < word2.length)
15+
{
1416
result += word2.charAt(i);
17+
}
1518

1619
}
1720

1821
return result;
1922
}
2023

21-
// Driver code
24+
2225
let word1 = "abc";
2326
let word2 = "pqr";
2427
console.log(mergeAlternately(word1, word2));
25-
//This code is Contributed by chinmaya121221

0 commit comments

Comments
 (0)