Skip to content

Commit 7a0ba1a

Browse files
author
Kyle Maune
committed
added second solution for caesar cipher
1 parent f05954a commit 7a0ba1a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Medium Difficulty/caesarCipher2.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// coderbyte solution for caesar cipher
2+
// splashinn
3+
4+
function CaesarCipher(str, num) {
5+
return str.replace(/./g, function (l) {
6+
var c = l.charCodeAt();
7+
if (c >= 65 && c <= 90) {
8+
c += num;
9+
return String.fromCharCode(c > 90 ? 65 + c - 91 : c);
10+
}
11+
if (c >= 97 && c <= 122) {
12+
c += num;
13+
return String.fromCharCode(c > 122 ? 97 + c - 123 : c);
14+
}
15+
return l;
16+
});
17+
18+
}

0 commit comments

Comments
 (0)