Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isleOfMan(arr = []) {
  2.     const pattern = /^([#$%*&])([A-Za-z]+)\1=(\d+)!!(.+)/;
  3.  
  4.     for (let i = 0; i < arr.length; i++) {
  5.         const matches = pattern.exec(arr[i]);
  6.  
  7.         if (matches) {
  8.             const [, , racer, length, geohash] = matches;
  9.  
  10.             if (Number(length) !== geohash.length) {
  11.                 console.log('Nothing found!');
  12.  
  13.                 continue;
  14.             }
  15.  
  16.             const decryptedGeohash = geohash
  17.                 .split('')
  18.                 .map(char => {
  19.                     const charCode = char.charCodeAt(0);
  20.  
  21.                     return String.fromCharCode(charCode + Number(length));
  22.                 })
  23.                 .join('');
  24.  
  25.             console.log(`Coordinates found! ${racer} -> ${decryptedGeohash}`);
  26.  
  27.             return;
  28.         } else {
  29.             console.log('Nothing found!');
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement