Advertisement
svephoto

Destination Mapper [JavaScript]

Apr 2nd, 2021
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let regex = /(=|\/)(?<country>[A-Z][A-Za-z]{2,})\1/g;
  3.     let matches = input.match(regex);
  4.     let countries = [];
  5.     let travelPoints = 0;
  6.  
  7.     if(matches) {
  8.         for(let line of matches) {
  9.             regex = /(=|\/)(?<country>[A-Z][A-Za-z]{2,})\1/g;  
  10.             let exec = regex.exec(line);
  11.             countries.push(exec.groups.country);
  12.             travelPoints += exec.groups.country.length;
  13.         }
  14.     }
  15.  
  16.     console.log(`Destinations: ${countries.join(', ')}`);
  17.     console.log(`Travel Points: ${travelPoints}`);
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement