Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let text = input[0];
  4. let [replacement, replaced] = input[1].split(' ');
  5. let newText = '';
  6. let value = '';
  7.  
  8. //decode the text
  9. for (let elem of text) {
  10. value = elem.charCodeAt(elem) - 3;
  11. newText += String.fromCharCode(value);
  12. }
  13.  
  14. //replace word in the string
  15. while (newText.includes(replacement)) {
  16. newText = newText.replace(replacement, replaced);
  17. }
  18.  
  19. //check validity
  20.  
  21. for (let ch of newText) {
  22. let current = newText.charCodeAt(ch);
  23. let check = current >= 100 && current <= 125 || current === 35;
  24. if (!check) {
  25. console.log('This is not the book you are looking for.');
  26. return
  27. }
  28. }
  29. console.log(newText);
  30.  
  31. }
  32.  
  33. solve(['wkhfn#|rx#jhqfkr#phf#exw#|rxu#uholf#lv#khfgohg#lq#hfrwkhu#sohfhw',
  34. 'ec an']);
  35.  
  36.  
  37. solve([ 'arx#vkdww#qrw#sdvv', 't l' ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement