victoriaSD

Untitled

Mar 15th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function destinationMapper(string) {
  2.   let travelPoints = 0;
  3.   let words = [];
  4.  
  5.   for (let i = 0; i < string.length; i++) {
  6.     let symbol = string[i];
  7.     let word = "";
  8.  
  9.     if (symbol === "=" || symbol === "/") {
  10.       let nextSymbol = string[i + 1];
  11.  
  12.       if (nextSymbol === nextSymbol.toUpperCase()) {
  13.         word += nextSymbol;
  14.  
  15.         for (let j = i + 2; j < string.length; j++) {
  16.           let letter = string[j];
  17.  
  18.           if (letter.match(/[a-z]/i)) {
  19.             word += letter;
  20.           } else if (letter === symbol && word.length >= 3) {
  21.             words.push(word);
  22.             travelPoints += word.length;
  23.             i = j;
  24.             break;
  25.           } else {
  26.             break;
  27.           }
  28.         }
  29.       }
  30.     }
  31.   }
  32.  
  33.   console.log(`Destinations: ${words.join(", ")}`);
  34.   console.log(`Travel Points: ${travelPoints}`);
  35. }
  36. destinationMapper("=Hawai=/Cyprus/=Invalid/invalid==i5valid=/I5valid/=i=");
Advertisement
Add Comment
Please, Sign In to add comment