Advertisement
divanov94

Untitled

Aug 9th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function destinationMapper(input){
  2.     let pattern = /([=/])(?<town>[A-Z][a-z]{2,})\1/g;
  3.  
  4.     let matches=[...input.matchAll(pattern)];
  5.     let points=0;
  6.     let valid=[];
  7.     for(let match of matches){
  8.         let town=match.groups["town"];
  9.         let len=Number(town.length);
  10.         points+=len;
  11.         valid.push(town);
  12.  
  13.  
  14.  
  15.  
  16.     }
  17.     console.log(`Destinations: ${valid.join(", ")}`);
  18.     console.log(`Travel Points: ${points}`)
  19.  
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement