Liliana797979

destination mapper - final exam - fundamentals

Aug 4th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function travel(input) {
  3.  
  4.  
  5.     let pattern = /([=|\/])[A-Z][A-Za-z]{2,}\1/g;
  6.  
  7.     let locations = []
  8.     let points = 0;
  9.  
  10.  
  11.     while ((match = pattern.exec(input)) != null) {
  12.         let wordPattern = /\w+/g;
  13.         let words = wordPattern.exec(match[0])
  14.         locations.push(words[0])
  15.        
  16.        
  17.        
  18.  
  19.     }
  20.  
  21.     for (let el of locations) {
  22.         points += el.length
  23.     }
  24.  
  25.  
  26.  
  27.  
  28.     console.log(`Destinations: ${locations.join(', ')}`)
  29.     console.log(`Travel Points: ${points}`);
  30.  
  31.  
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment