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.
functioncaesarCipher(s,k){// Write your code hereconstalphabet=Array.from('abcdefghijklmnopqrstuvwxyz');constupAlphabet=Array.from('abcdefghijklmnopqrstuvwxyz'.toUpperCase());letl=[]constarr=Array.from(s)constf=k%26arr.forEach(char=>{constisLetter=alphabet.includes(char)||upAlphabet.includes(char)constal=alphabet.includes(char)&&isLetter?alphabet:upAlphabet;if(isLetter){constindex=al.indexOf(char);if(index+k>al.length){constdex=index+f>=al.length?(index+f)-al.length:index+fl.push(al[dex])}elseif(index+k==al.length){l.push(al[0])}else{l.push(al[index+f])}}else{l.push(char)}})returnl.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 →
Solution in javascript: