maymunskoa

04.Santa's Secret Helper (RegExp)

Mar 22nd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let key = Number(input.shift());
  3.   let pattern = /@([A-Za-z]+)[^-@!\:>]*!([G])!/gm;
  4.   for (const word of input) {
  5.     if (word === "end") {
  6.       break;
  7.     }
  8.     let result = "";
  9.     for (const letter of word) {
  10.       result += String.fromCharCode(letter.charCodeAt() - key);
  11.     }
  12.     if (Array.from(result.matchAll(pattern)).length > 0) {
  13.       let behavior = Array.from(result.matchAll(pattern))[0][2];
  14.       let name = Array.from(result.matchAll(pattern))[0][1];
  15.       console.log(name);
  16.     }
  17.   }
  18. }
Add Comment
Please, Sign In to add comment