Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function solve(arr){
  2. let num = Number(arr.shift()) // got length of array
  3. let pattern = /\|[A-Z]{4,}\|\:\#[A-Za-z]+\ [A-Za-z]+\#/g //the regex pattern
  4. for(let i = 0; i < num; i++){
  5. if(arr[i].match(pattern)){
  6. let line = arr[i].split('|:#') // [ '|IVAN', 'Master detective#' ]
  7. let name = line[0].slice(1) // IVAN removed '|'
  8. let occupation = line[1].slice(0, line[1].length -1) // Master detective removed '#'
  9. console.log(`${name}, The ${occupation}`);
  10. console.log(`>> Strength: ${name.length}`);
  11. console.log(`>> Armour: ${occupation.length}`);
  12. }
  13. else{
  14. console.log('Access denied!');
  15. }
  16. }
  17. }
  18. solve(
  19. [
  20. '3',
  21. '|PETER|:#H1gh Overseer#',
  22. '|IVAN|:#Master detective#',
  23. '|KARL|: #Marketing lead#'
  24.  
  25.  
  26. ]
  27. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement