Advertisement
VeselaVideva

Final Exam 13.12.2020 - Problem 02

Dec 19th, 2020
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function problemTwo(input) {
  2.     let pattern = /!(?<command>[A-Z][a-z]{2,})!\:\[(?<message>[A-Za-z]{7,})\]/g
  3.  
  4.     let commands = input.shift();
  5.     commands = Number(commands);
  6.     let result = '';
  7.  
  8.     for (let line of input) {
  9.         let match = line.match(pattern);
  10.  
  11.         if (match !== null) {
  12.             match = pattern.exec(line);
  13.             let message = match.groups.message;
  14.             result += `${match.groups.command}: `;
  15.  
  16.             for (let i = 0; i < message.length; i++) {
  17.                 let value = message.charCodeAt(i);
  18.                 result += value + ' ';
  19.             }
  20.             console.log(result);
  21.         } else {
  22.             console.log(`The message is invalid`);
  23.         }
  24.  
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement