Advertisement
bebo231312312321

Untitled

Apr 2nd, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function messageTranslator(input){
  2.  let n = input.shift();
  3.  let pattern = /[!](?<command>[A-Z][a-z]{2,})[!][:][[](?<word>[A-Za-z]{8,})[\]]/;
  4.  let numbers = [];
  5.  
  6.  for(let i = 0; i < n; i++){
  7.     let match = pattern.exec(input[i]);
  8.  
  9.    
  10.     if(match){
  11.  
  12.     let word = match[2];
  13.     let command = match[1];
  14.     for(let char of word){
  15.         numbers.push(char.charCodeAt());
  16.     }
  17.     console.log(`${command}: ${numbers.join(' ')}`)
  18.  
  19.     } else {
  20.         console.log(`The message is invalid`);
  21.     }
  22.  }
  23.  
  24.  
  25.  
  26. }
  27. messageTranslator((["2",
  28. "!Send!:[IvanisHere]",
  29. "*Time@:[Itis5amAlready"])
  30. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement