Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function destinationMapper(string) {
- let travelPoints = 0;
- let words = [];
- for (let i = 0; i < string.length; i++) {
- let symbol = string[i];
- let word = "";
- if (symbol === "=" || symbol === "/") {
- let nextSymbol = string[i + 1];
- if (nextSymbol === nextSymbol.toUpperCase()) {
- word += nextSymbol;
- for (let j = i + 2; j < string.length; j++) {
- let letter = string[j];
- if (letter.match(/[a-z]/i)) {
- word += letter;
- } else if (letter === symbol && word.length >= 3) {
- words.push(word);
- travelPoints += word.length;
- i = j;
- break;
- } else {
- break;
- }
- }
- }
- }
- }
- console.log(`Destinations: ${words.join(", ")}`);
- console.log(`Travel Points: ${travelPoints}`);
- }
- destinationMapper("=Hawai=/Cyprus/=Invalid/invalid==i5valid=/I5valid/=i=");
Advertisement
Add Comment
Please, Sign In to add comment