Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 84ba176

Browse files
committed
Add a question
1 parent 667f7d7 commit 84ba176

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,3 +1446,35 @@ const kidsWithCandies = (candies, extraCandies) => {
14461446
---
14471447

14481448
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
1449+
1450+
## 44. Rot13
1451+
1452+
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.
1453+
1454+
```js
1455+
const rot13 = str => {
1456+
// Your solution
1457+
};
1458+
1459+
console.log(rot13('az AZ')); // nm NM
1460+
console.log(rot13('10+2 is twelve.')); // 10+2 vf gjryir.
1461+
console.log(rot13('abcdefghijklmnopqrstuvwxyz')); // nopqrstuvwxyzabcdefghijklm
1462+
```
1463+
1464+
<details><summary>Solution</summary>
1465+
1466+
```js
1467+
const rot13 = str => {
1468+
return str.replace(/[a-z]/gi, letter =>
1469+
String.fromCharCode(
1470+
letter.charCodeAt() + (letter.toLowerCase() <= 'm' ? 13 : -13)
1471+
)
1472+
);
1473+
};
1474+
```
1475+
1476+
</details>
1477+
1478+
---
1479+
1480+
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /