maymunskoa

01. Arriving in Kathmandu (Tech Fundamentals 140419)

Mar 25th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.     let pattern = /^(?<name>[A-Za-z0-9!@#\$\?]+)=(?<count>\d+)<<(?<hash>\S+)$/;
  3.    
  4.     for (const line of input) {
  5.         if(line === 'Last note'){
  6.             break;
  7.         }
  8.         if(line.match(pattern) !== null){
  9.                 let result = line.match(pattern).groups;
  10.                 let rawName = result.name;
  11.                 let count = Number(result.count);
  12.                 let hash = result.hash;
  13.                 let namehelper = rawName.split(/[!@#\$\?]*/g);
  14.                 let name = namehelper.join('');
  15.                 if(count === hash.length){
  16.                     console.log(`Coordinates found! ${name} -> ${hash}`);
  17.                    
  18.                 }else{
  19.                     console.log(`Nothing found!`);
  20.                 }
  21.         }else{
  22.             console.log(`Nothing found!`);
  23.            
  24.         }
  25.        
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment