Skip to content

Commit cf66aeb

Browse files
committed
Morse_code / 기초
1 parent 27626e2 commit cf66aeb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tkddbs587/Hash/Morse_code.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function solution(letter) {
2+
// 모스 부호 객체
3+
morse = {
4+
".-": "a",
5+
"-...": "b",
6+
"-.-.": "c",
7+
"-..": "d",
8+
".": "e",
9+
"..-.": "f",
10+
"--.": "g",
11+
"....": "h",
12+
"..": "i",
13+
".---": "j",
14+
"-.-": "k",
15+
".-..": "l",
16+
"--": "m",
17+
"-.": "n",
18+
"---": "o",
19+
".--.": "p",
20+
"--.-": "q",
21+
".-.": "r",
22+
"...": "s",
23+
"-": "t",
24+
"..-": "u",
25+
"...-": "v",
26+
".--": "w",
27+
"-..-": "x",
28+
"-.--": "y",
29+
"--..": "z",
30+
};
31+
32+
// letter의 모스 부호가 공백 기준으로 나눠져있으므로 split를 통해 배열로 변환
33+
// 변환된 배열을 map을 통해 순회하며 morse 객체의 키와 일치하는 영어 문자열 value로 이루어진 새 배열 반환
34+
// 영어 배열을 join을 통해 문자열로 변환
35+
return letter
36+
.split(" ")
37+
.map((el) => morse[el])
38+
.join("");
39+
}

0 commit comments

Comments
 (0)