Morse Code Translator

Translate a string into morse code.

Easy1/7/2024

Problem statement

Your task is to write a program that takes a string as input and translates it into its equivalent in international Morse code. The input will be a string of lowercase space-separated words where each word consists of nothing but the letters a-z. Add spaces between the words but not between the letters of a word in morse code. Here is the alphabet in morse code:

a: .-      g: --.     m: --      s: ...     y: -.--  
b: -...    h: ....    n: -.      t: -       z: --..  
c: -.-.    i: ..      o: ---     u: ..-     
d: -..     j: .---    p: .--.    v: ...-    
e: .       k: -.-     q: --.-    w: .--     
f: ..-.    l: .-..    r: .-.     x: -..-    

For example, the string

lorem ipsum

should be translated to

.-..---.-..-- ...--......---

Problem leaderboard

#
Size
%
Users
#1
101 c.
Top 5%
Shanethegamer
#2
102 c.
Top 11%
tree
#3
113 c.
Top 16%
AlephSquirrel
#4
124 c.
Top 21%
sean
#5
133 c.
Top 26%
Natanaelel
#6
136 c.
Top 32%
cers
#7
139 c.
Top 37%
val
#8
140 c.
Top 42%
voytxt
#9
145 c.
Top 47%
Thomasdcrt
#10
150 c.
Top 53%
scpchicken
#11
162 c.
Top 58%
SephQ
#12
170 c.
Top 63%
davyboyh
#13
172 c.
Top 68%
maximec-indy
#14
174 c.
Top 74%
Pascal
#15
195 c.
Top 79%
ComputerKWasTaken
#16
219 c.
Top 84%
KrausRaus
#17
258 c.
Top 89%
madeforlosers
#18
593 c.
Top 95%
jules
#19
606 c.
Top 100%
Arnaud