Skip to content

Commit f05954a

Browse files
author
Kyle Maune
committed
added solution for caesar cipher
1 parent 5942d4e commit f05954a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Medium Difficulty/caesarCipher.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// coderbyte solution for caesar cipher
2+
// splashinn
3+
4+
function caesarCipher(str, num) {
5+
var result = new Array(str.length);
6+
for (var i = 0; i < str.length; i++) {
7+
if ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".indexOf(str[i]) !== -1) {
8+
var code = str[i].charCodeAt(0) + num;
9+
result[i] = String.fromCharCode(code);
10+
} else {
11+
result[i] = str[i];
12+
}
13+
}
14+
return result.join("");
15+
}

0 commit comments

Comments
 (0)