-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrot13.js
More file actions
49 lines (48 loc) · 1019 Bytes
/
rot13.js
File metadata and controls
49 lines (48 loc) · 1019 Bytes
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
// https://www.codewars.com/kata/52223df9e8f98c7aa7000062/train/javascript
function rot13(str) {
const dict = {
'n':'a',
'o':'b',
'p':'c',
'q':'d',
'r':'e',
's':'f',
't':'g',
'u':'h',
'v':'i',
'w':'j',
'x':'k',
'y':'l',
'z':'m',
'a':'n',
'b':'o',
'c':'p',
'd':'q',
'e':'r',
'f':'s',
'g':'t',
'h':'u',
'i':'v',
'j':'w',
'k':'x',
'l':'y',
'm':'z',
}
const arr = str.split("")
const letters = /^[A-Za-z]+$/
let ans = arr.map(element => {
let rep
if (!letters.test(element)) {
return element
}
if (element === element.toLowerCase()) {
rep = dict[element]
}
else {
rep = dict[element.toLowerCase()].toUpperCase()
}
return rep
});
return ans.join("")
}
console.log(rot13("EBG13 rknzcyr"))