Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // it gives me 70/100. It shall be refined.
- function winningTicket(inputStr) {
- let inputData = inputStr;
- let inputArr = inputStr.split(",");
- for ( let winnerTicket of inputArr){
- let currentTicket = winnerTicket.trim();
- let patternWinnerTicket = /[\d\w\s]*(?<leftPart>[@#$^]{6,})[\d\w\s]*(?<rigthPart>\1)/g;
- let matchArr = patternWinnerTicket.exec(currentTicket);
- if ( currentTicket.length != 20){
- console.log(`invalid ticket`);
- } else {
- if ( matchArr === null){
- console.log(`ticket "${currentTicket}" - no match`);
- }
- if ( matchArr !== null ){
- // console.log(matchArr);
- let leftportion = matchArr.groups.leftPart;
- let rightportion = matchArr.groups.rigthPart;
- if ( leftportion.length>=6 && leftportion.length<=9 ){
- console.log(`ticket "${currentTicket.trim()}" - ${leftportion.length}${leftportion.charAt(0)}`);
- } else if (leftportion.length == 10){
- console.log(`ticket "${currentTicket.trim()}" - ${leftportion.length}${leftportion.charAt(0)} Jackpot!`);
- }
- }
- }
- }
- }
- winningTicket("Cash$$$$$$Ca$$$$$$sh");
- console.log(`********`);
- winningTicket("$$$$$$$$$$$$$$$$$$$$, aabb , th@@@@@@eemo@@@@@@ey");
- console.log(`********`);
- winningTicket("validticketnomatch:(");
- // (?<leftPart>[@#$^]{6,})[\W\D\w\d]*(?<rigthPart>\1)
- // [\d\w\s]*(?<leftPart>[@#$^]{6,})[\d\w\s]*(?<rigthPart>\1)
- // (?<winSymbolsLeft>[@#$^]+)([\w]+)(?<winSymboslRight>\k<winSymbolsLeft>)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement