Liliana797979

destination mapper - final exam

Aug 8th, 2021
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function destination(input) {
  2.     let pattern = /[=|\/]([A-Z][A-Za-z]){2,}\1/g;
  3.  
  4.     let locations = [];
  5.     let points = 0;
  6.  
  7.     while ((match = pattern.exec(input)) != null) {
  8.         let wordPattern = /\w+/g;
  9.         let words = wordPattern.exec(match[0]);
  10.         locations.push(words[0]);
  11.     }
  12.     for (let element of locations) {
  13.         points += element.length;
  14.     }
  15.     console.log(`Destinations: ${locations.join(", ")}`);
  16.     console.log(`Travel Points: ${points}`);
  17. }
  18.  
  19. destination("=Hawai=/Cyprus/=Invalid/invalid==i5valid=/I5valid/=i=");
Advertisement
Add Comment
Please, Sign In to add comment