Advertisement
vladovip

RegExp_WinningTicket_JS FUND

Sep 5th, 2022
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  // it gives me 70/100. It shall be refined.
  2.  
  3. function winningTicket(inputStr) {
  4.   let inputData = inputStr;
  5.   let inputArr = inputStr.split(",");
  6.  
  7.     for ( let winnerTicket of inputArr){
  8.  
  9.     let currentTicket =   winnerTicket.trim();  
  10.     let patternWinnerTicket = /[\d\w\s]*(?<leftPart>[@#$^]{6,})[\d\w\s]*(?<rigthPart>\1)/g;
  11.     let matchArr = patternWinnerTicket.exec(currentTicket);
  12.  
  13.     if ( currentTicket.length != 20){
  14.         console.log(`invalid ticket`);
  15.     } else {
  16.  
  17.         if (  matchArr === null){
  18.             console.log(`ticket "${currentTicket}" - no match`);
  19.         }
  20.  
  21.         if ( matchArr !== null  ){
  22.             // console.log(matchArr);
  23.             let leftportion = matchArr.groups.leftPart;
  24.             let rightportion = matchArr.groups.rigthPart;
  25.            
  26.             if ( leftportion.length>=6 && leftportion.length<=9 ){
  27.              console.log(`ticket "${currentTicket.trim()}" - ${leftportion.length}${leftportion.charAt(0)}`);
  28.             } else if (leftportion.length == 10){
  29.             console.log(`ticket "${currentTicket.trim()}" - ${leftportion.length}${leftportion.charAt(0)} Jackpot!`);
  30.             }  
  31.         }
  32.     }
  33.  
  34.     }
  35.  
  36. }
  37.  
  38.  
  39.  
  40. winningTicket("Cash$$$$$$Ca$$$$$$sh");
  41. console.log(`********`);
  42. winningTicket("$$$$$$$$$$$$$$$$$$$$, aabb  , th@@@@@@eemo@@@@@@ey");
  43. console.log(`********`);
  44. winningTicket("validticketnomatch:(");
  45.  
  46. // (?<leftPart>[@#$^]{6,})[\W\D\w\d]*(?<rigthPart>\1)
  47.  
  48. // [\d\w\s]*(?<leftPart>[@#$^]{6,})[\d\w\s]*(?<rigthPart>\1)
  49.  
  50.  
  51.  
  52. // (?<winSymbolsLeft>[@#$^]+)([\w]+)(?<winSymboslRight>\k<winSymbolsLeft>)
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement