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.
// Write your code hereletcaps=[65,90]//Capital letters Charcode Start, Endletsmall=[97,122]// Small letters Charcode start, endletoutput=''k=k%26// k divised by alpha lengths.split('').forEach((a)=>{if(caps[0]<=a.charCodeAt()&&a.charCodeAt()<=caps[1]){if(a.charCodeAt()+k<=caps[1]){output+=String.fromCharCode((a.charCodeAt()+k))}else{letcurrent=a.charCodeAt()+kletmax=caps[1]output+=String.fromCharCode(((caps[0])+(current-max)-1))}}elseif(small[0]<=a.charCodeAt()&&a.charCodeAt()<=small[1]){if(a.charCodeAt()+k<=small[1]){output+=String.fromCharCode((a.charCodeAt()+k))}else{letcurrent=a.charCodeAt()+kletmax=small[1]output+=String.fromCharCode(((small[0])+(current-max)-1))}}else{output+=a// Return if not an alphabit}})returnoutput
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 →
Javascript Solution: