FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/Ciphers/MorseCode.js at master · TheAlgorithms/JavaScript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
TheAlgorithms
/
JavaScript
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
5.8k
Star
34.2k
Code
Issues
21
Pull requests
192
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
Ciphers
/
MorseCode.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
90 lines (86 loc) · 1.79 KB
Breadcrumbs
JavaScript
/
Ciphers
/
MorseCode.js
Copy path
File metadata and controls
90 lines (86 loc) · 1.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
*
@author
mrmagic2020
*
@description
Enciphers a combination of letters, numbers and symbols into morse code.
*
@see
https://en.wikipedia.org/wiki/Morse_code
*
@param
{
string
} msg The message to be enciphered.
*
@param
{
string
} dot Symbol representing the dots.
*
@param
{
string
} dash Symbol representing the dash.
*
@returns
{
string
} Enciphered morse code.
*
@example
morse('Hello World!') = '**** * *-** *-** --- *-- --- *-* *-** -** -*-*--'
*/
const
morse
=
(
msg
,
dot
=
'*'
,
dash
=
'-'
)
=>
{
const
key
=
{
A
:
'*-'
,
B
:
'-***'
,
C
:
'-*-*'
,
D
:
'-**'
,
E
:
'*'
,
F
:
'**-*'
,
G
:
'--*'
,
H
:
'****'
,
I
:
'**'
,
J
:
'*---'
,
K
:
'-*-'
,
L
:
'*-**'
,
M
:
'--'
,
N
:
'-*'
,
O
:
'---'
,
P
:
'*--*'
,
Q
:
'--*-'
,
R
:
'*-*'
,
S
:
'***'
,
T
:
'-'
,
U
:
'**-'
,
V
:
'***-'
,
W
:
'*--'
,
X
:
'-**-'
,
Y
:
'-*--'
,
Z
:
'--**'
,
1
:
'*----'
,
2
:
'**---'
,
3
:
'***--'
,
4
:
'****-'
,
5
:
'*****'
,
6
:
'-****'
,
7
:
'--***'
,
8
:
'---**'
,
9
:
'----*'
,
0
:
'-----'
,
'.'
:
'*-*-*-'
,
','
:
'--**--'
,
'?'
:
'**--**'
,
'!'
:
'-*-*--'
,
"'"
:
'*----*'
,
'"'
:
'*-**-*'
,
'('
:
'-*--*'
,
')'
:
'-*--*-'
,
'&'
:
'*-***'
,
':'
:
'---***'
,
';'
:
'-*-*-*'
,
'/'
:
'-**-*'
,
_
:
'**--*-'
,
'='
:
'-***-'
,
'+'
:
'*-*-*'
,
'-'
:
'-****-'
,
$
:
'***-**-'
,
'@'
:
'*--*-*'
}
let
newMsg
=
''
msg
.
toString
(
)
.
split
(
''
)
.
forEach
(
(
e
)
=>
{
if
(
/
[
a
-
z
A
-
Z
]
/
.
test
(
e
)
)
{
newMsg
+=
key
[
e
.
toUpperCase
(
)
]
.
replaceAll
(
'*'
,
dot
)
.
replaceAll
(
'-'
,
dash
)
}
else
if
(
Object
.
keys
(
key
)
.
includes
(
e
)
)
{
newMsg
+=
key
[
e
]
.
replaceAll
(
'*'
,
dot
)
.
replaceAll
(
'-'
,
dash
)
}
else
{
newMsg
+=
e
}
newMsg
+=
' '
}
)
return
newMsg
.
trim
(
)
}
export
{
morse
}
Back
|
FazBrowse Home
|
New Git URL