Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Dec 24, 2023
1 parent 50c3e40 commit 27b1bdc
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Runtime: O(N), N = number of characters
// Space: O(N)

function getChar(char, key) {
let charCode = ((char.charCodeAt() - 97 + key) % 26) + 97;
return String.fromCharCode(charCode);
}

function caesarCipherEncryptor(string, key) {
return [...string].map((char) => getChar(char, key)).join('');
}

0 comments on commit 27b1bdc

Please sign in to comment.