We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
constct=25functioncaesarCipher(s:string,k:number):string{// 0. reduce k by 26 (1 circle rotation)k=k%(ct+1)// 1. map character and rotation, skip special and numberreturns.split('').map(char=>{if(!/[a-zA-Z]/.test(char))returnchar;letcode=char.charCodeAt(0)letmile=char==char.toUpperCase()?65:97if(code+k>mile+ct)returnString.fromCharCode(code+k-ct-1)returnString.fromCharCode(code+k)}).join('')}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Caesar Cipher
You are viewing a single comment's thread. Return to all comments →
My answer with Typescript