Advertisement
divanov94

Untitled

Aug 3rd, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function messageTranslator(input) {
  2.    let countMessage=Number(input.shift());
  3.    let pattern=/!(?<command>[A-Z][a-z]{3,})!:\[(?<text>[A-Za-z]+)\]/g;
  4.    let output=[];
  5.    for(let i=0;i<countMessage;i++){
  6.        let message=input.shift();
  7.        let result=pattern.exec(message);
  8.        if(result!==null){
  9.            let command=result.groups["command"];
  10.            let toEncrypt=result.groups["text"];
  11.            output.push(command);
  12.  
  13.            for(let i=0;i<toEncrypt.length;i++){
  14.                ch=toEncrypt[i].charCodeAt(0);
  15.                output.push(ch);
  16.  
  17.  
  18.  
  19.            }
  20.            console.log(output.join(" "));
  21.  
  22.  
  23.  
  24.  
  25.        }else {
  26.            console.log(`The message is invalid`)
  27.        }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.        }
  35.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement