Advertisement
Guest User

Untitled

a guest
Jul 10th, 2022
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr){
  2.     let pattern = /(?=.{20}).*?(?=(?<ch>[@#$^]))(?<match>\k<ch>{6,}).*(?<=.{10})\k<match>.*/;
  3.  
  4.     arr = arr[0].trim().split(/\s*,\s*/);
  5.     for (let line of arr){
  6.         let match = pattern.exec(line);
  7.  
  8.         if (match){
  9.             if (match.groups.match.length >= 6 && match.groups.match.length <= 9){
  10.                 console.log(`ticket "${line}" - ${match.groups.match.length}${match.groups.ch}`)
  11.             } else if (match.groups.match.length == 10){
  12.                 console.log(`ticket "${line}" - ${match.groups.match.length}${match.groups.ch} Jackpot!`)                                
  13.             }          
  14.         } else if (line.length !== 20){
  15.             console.log('invalid ticket')
  16.         } else {
  17.             console.log(`ticket "${line}" - no match`)
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement