나는 이렇게 학습한다/Algorithm & SQL

0107. Exclamation marks series #4: Remove all exclamation marks from sentence but ensure a exclamation mark at the end of string

daco2020 2023. 1. 7. 23:23
반응형

Description:

Remove all exclamation marks from sentence but ensure a exclamation mark at the end of string. For a beginner kata, you can assume that the input data is always a non empty string, no need to verify it.

Examples

remove("Hi!") === "Hi!"
remove("Hi!!!") === "Hi!"
remove("!Hi") === "Hi!"
remove("!Hi!") === "Hi!"
remove("Hi! Hi!") === "Hi Hi!"
remove("Hi") === "Hi!"



Solution:

const remove = (string) => string.replace(/!/g, "") + "!"


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

0109. A Needle in the Haystack  (0) 2023.01.09
0108. How many lightsabers do you own?  (0) 2023.01.09
0106. Is there a vowel in there?  (0) 2023.01.07
0105. Greet Me  (0) 2023.01.05
0104. Sleigh Authentication  (0) 2023.01.04