nikolayneykov

Untitled

Apr 6th, 2019
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve ([encryptedSting, substrings]) {
  2.   if (!encryptedSting.match(/^[d-z{}|#\s]+$/)) {
  3.     console.log('This is not the book you are looking for.')
  4.   } else {
  5.     let [firstSubstring, secondSubstring] = substrings.split(' ')
  6.     let decryptedString = encryptedSting
  7.       .split('')
  8.       .map(x => String.fromCharCode(x.charCodeAt(0) - 3))
  9.       .join('')
  10.       .replace(new RegExp(firstSubstring, 'g'), secondSubstring)
  11.  
  12.     console.log(decryptedString)
  13.   }
  14. }
Add Comment
Please, Sign In to add comment