Advertisement
TZinovieva

Destination Mapper JS Fundamentals

Mar 30th, 2023
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function destinationMapper(input) {
  2.     let regex = /(=|\/)(?<place>[A-Z][a-zA-Z]{2,})\1/g;
  3.     let matches;
  4.     let places = [];
  5.     let totalLength = 0;
  6.  
  7.     while ((matches = regex.exec(input)) !== null) {
  8.         places.push(matches.groups.place);
  9.         totalLength += matches.groups.place.length;
  10.     }
  11.  
  12.     console.log(`Destinations: ${places.join(', ')}`);
  13.     console.log(`Travel Points: ${totalLength}`);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement