DEV Community

Discussion on: Daily Challenge #42 - Caesar Cipher

Collapse
 
kvharish profile image
K.V.Harish • Edited

My solution in js

const encode = (sentence, key) => sentence.split(' ')
                                          .map((word) => word.split('')
                                          .map((char) => (/[a-z]/i.test(char)) ? String.fromCharCode(char.charCodeAt(0) + key) : char)
                                          .join(''))
                                          .join(' ');