Advertisement
vladovip

The Racer_ JS FUND

Apr 16th, 2022
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Racer(inputArr) {
  2.   let patternRegex = /^([#$%*&])(?<nameRacer>[A-Za-z]+)\1=(?<LengthCode>\d+)!!(?<Code>.+)$/;
  3.   let racersObj = {};
  4.  
  5.   for ( let index = 0; index < inputArr.length; index ++ ) {
  6.     let currentText = inputArr[index];
  7.     // console.log(currentText);
  8.     let match = patternRegex.exec(currentText);
  9.  
  10.     if (match !== null) {
  11.       let racer = match.groups.nameRacer;
  12.       let length = Number(match.groups.LengthCode);
  13.       let encryptedCode = match.groups.Code;
  14.      
  15.       // console.log(racer,length,encryptedCode);
  16.       if (length == encryptedCode.length) {
  17.         let arrOfEncryptCode = encryptedCode.split("");
  18.         // console.log(arrOfEncryptCode);
  19.         let newStr = arrOfEncryptCode.map((x) => x.charCodeAt() + length).map((x) => (x = String.fromCharCode(x))).join("");
  20.         // let newStr = tempArr.map(x => x = String.fromCharCode(x)).join("");
  21.         // console.log(newStr);
  22.         racersObj[racer] = newStr;
  23.         console.log(`Coordinates found! ${racer} -> ${racersObj[racer]}`);
  24.       }
  25.     }  else {
  26.         console.log(`Nothing found!`);
  27.     }
  28.  
  29.   }
  30. }
  31.  
  32. Racer([
  33.   "%GiacomoAgostini%=7!!hbqw",
  34.   "&GeoffDuke*=6!!vjh]zi",
  35.   "JoeyDunlop=10!!lkd,rwazdr",
  36.   "Mike??Hailwood=5!![pliu",
  37.   "#SteveHislop#=16!!df%TU[Tj(h!!TT[S",
  38. ]);
  39.  
  40. console.log(`---------`);
  41.  
  42. Racer([
  43.   "Ian6Hutchinson=7!!(58ycb4",
  44.   "#MikeHailwood#!!'gfzxgu6768=11",
  45.   "slop%16!!plkdek/.8x11ddkc",
  46.   "$Steve$=9Hhffjh",
  47.   "*DavMolyneux*=15!!efgk#'_$&UYV%h%",
  48.   "RichardQ^uayle=16!!fr5de5kd",
  49. ]);
  50.  
  51. //  ^([#$%*&])(?<nameRacer>[A-Za-z]+)\1=(?<LengthCode>\d+)!!(?<Code>\w+)
  52.  
  53. //  ^([#$%*&])(?<nameRacer>[A-Za-z]+)\1=(?<LengthCode>\d+)!!(?<Code>\w+)
  54.  
  55. // ([#$%*&])(?<nameRacer>[A-Za-z]+)\1=(?<LengthCode>\d+)!!(?<Code>.+)
  56.  
  57. // ^([#$%*&])(?<nameRacer>[A-Za-z]+)\1=(?<LengthCode>\d+)!!(?<Code>.+)$
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement