Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
14
Task/Caesar-cipher/TypeScript/caesar-cipher.type
Normal file
14
Task/Caesar-cipher/TypeScript/caesar-cipher.type
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function replace(input: string, key: number) : string {
|
||||
return input.replace(/([a-z])/g,
|
||||
($1) => String.fromCharCode(($1.charCodeAt(0) + key + 26 - 97) % 26 + 97)
|
||||
).replace(/([A-Z])/g,
|
||||
($1) => String.fromCharCode(($1.charCodeAt(0) + key + 26 - 65) % 26 + 65));
|
||||
}
|
||||
|
||||
// test
|
||||
var str = 'The five boxing wizards jump quickly';
|
||||
var encoded = replace(str, 3);
|
||||
var decoded = replace(encoded, -3);
|
||||
|
||||
console.log('Enciphered: ' + encoded);
|
||||
console.log('Deciphered: ' + decoded);
|
||||
Loading…
Add table
Add a link
Reference in a new issue