https://www.codewars.com/kata/530e15517bc88ac656000716
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
ROT13 is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is an example of the Caesar cipher.
Create a function that takes a string and returns the string ciphered with Rot13. If there are numbers or special characters included in the string, they should be returned as they are. Only letters from the latin/english alphabet should be shifted, like in the original Rot13 "implementation".
코드
function rot13(message){
const origin = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const cipher = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"
return message.replace(/[a-z]/gi, l => cipher[origin.indexOf(l)]);
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Break camelCase (6 kyu) / JavaScript (0) | 2023.02.14 |
---|---|
[Codewars] Grasshopper - Grade book (8 kyu) / JavaScript (0) | 2023.02.13 |
[Codewars] Area or Perimeter (8 kyu) / JavaScript (0) | 2023.02.11 |
[Codewars] Transportation on vacation (8 kyu) / JavaScript (0) | 2023.02.10 |
[Codewars] Write Number in Expanded Form (6 kyu) / JavaScript (0) | 2023.02.09 |
댓글