-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrom13.js
More file actions
32 lines (28 loc) · 967 Bytes
/
rom13.js
File metadata and controls
32 lines (28 loc) · 967 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
// let romthirteen = (string) => {
// let cut = string.split(" ")
// const upperShift = (letter) => {
// let num = letter.charCodeAt()
// num + 13 >= 91 ? num -= 13 : num +=13
// return String.fromCharCode(num)
// }
// const lowerShift = (letter) => {
// let num = letter.charCodeAt()
// num + 13 >= 123 ? num -= 13 : num += 13
// return String.fromCharCode(num)
// }
// return cut.map((place) => {
// let shift = []
// for (let letters of place) {
// !/[a-zA-z]/.test(letters) ? shift.push(letters) :
// (letters.toUpperCase() === letters ? shift.push(upperShift(letters)) :
// shift.push(lowerShift(letters)))
// }
// return shift.join('')
// }).join(' ')
// }
const rom13 = (string) => {
return string.replace(/[a-z]/gi,(place) => {
return String.fromCharCode(place.charCodeAt() + (place.toUpperCase().localeCompare('M') > 0 ? -13 : 13))
})
}
console.log(rom13('Ruby is coo;!'))