Liliana797979

problem 2_6 final exam

Aug 14th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.      
  3. function solve(input) {
  4.     let enteredN = Number(input.shift());
  5.     let pattern = /\|(?<boss>[A-Z]+)\|\:\#(?<title>[A-Z][a-z]+ [a-z]+)\#/g;
  6.     for (let i = 0; i < input.length; i++) {
  7.         if ((valid = pattern.exec(input[i])) !== null) {
  8.             let boss = valid.groups['boss'];
  9.             let title = valid.groups['title'];
  10.             let bossN = boss.length;
  11.             let titleN = title.length;
  12.             console.log(`${boss}, The ${title}`);
  13.             console.log(`>> Strength: ${bossN}`);
  14.             console.log(`>> Armour: ${titleN}`);
  15.            
  16.         } else {
  17.             console.log('Access denied!');
  18.            
  19.         }
  20.        
  21.     }
  22. }
  23. solve(['3',
  24. '|GEORGI|:#Lead architect#',
  25. '|Hristo|:#High Overseer#',
  26. '|STEFAN|:#Assistant Game Developer#']);
Advertisement
Add Comment
Please, Sign In to add comment