본문 바로가기

열정가득한 개발자의 이야기/Javascript Algorithm

1768. Merge Strings Alternately (JS)

반응형

 

hi. 

I've solved a problem related to strings.

It was simple, so I solved it right away. I'm so happy!

 

Anyway, I'm going to explain this problem.

There are two strings, and you need to combine them character by character, not string by string.

However, some strings have different lengths.
So, regardless of whether their lengths match or not, you should merge them one character at a time.

 

Here’s my solution:

I used an array to handle undefined elements, which occur due to different string lengths.

First, I pushed all the elements into the array.
Then, I rechecked the elements using forEach with typeof.

As a result, I passed all the test cases! 🎉

It's a small step, but I feel so happy seeing my skills improve day by day! 😊🚀

 

반응형