Skip to content

Commit c801b3e

Browse files
committed
--fix: missing case for -ve new index
1 parent c376de5 commit c801b3e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/_Classics_/caeser_cipher/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function caeserCipher(str, num) {
2323
newIndex -= totalAlphabets;
2424
}
2525

26+
if (newIndex < 0) {
27+
newIndex = totalAlphabets + newIndex;
28+
}
29+
2630
// check if the character in original string was upper case
2731
if (str[index] === alphabets[currentIndex].toUpperCase()) {
2832
result += alphabets[newIndex].toUpperCase();

0 commit comments

Comments
 (0)