ALSAVOV

Untitled

Oct 26th, 2023
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let index = 0;
  3.     let resultWord = "";
  4.     let secretWord = "";
  5.     let newWord = "";
  6.     let counterC = 0;
  7.     let counterO = 0;
  8.     let counterN = 0;
  9.  
  10.     let latinLetters = [
  11.         "a",
  12.         "b",
  13.         "c",
  14.         "d",
  15.         "e",
  16.         "f",
  17.         "g",
  18.         "h",
  19.         "i",
  20.         "j",
  21.         "k",
  22.         "l",
  23.         "m",
  24.         "n",
  25.         "o",
  26.         "p",
  27.         "q",
  28.         "r",
  29.         "s",
  30.         "t",
  31.         "u",
  32.         "v",
  33.         "w",
  34.         "x",
  35.         "y",
  36.         "z",
  37.     ];
  38.     let command = input[index];
  39.     index++;
  40.  
  41.     while (command !== "End") {
  42.         let currentLetter = command;
  43.  
  44.         if (latinLetters.includes(currentLetter.toLowerCase())) {
  45.             if (currentLetter.toLowerCase() === "c" && counterC === 0) {
  46.                 secretWord += currentLetter;
  47.                 counterC++;
  48.             } else if (currentLetter.toLowerCase() === "o" && counterO === 0) {
  49.                 secretWord += currentLetter;
  50.                 counterO++;
  51.             } else if (currentLetter.toLowerCase() === "n" && counterN === 0) {
  52.                 secretWord += currentLetter;
  53.                 counterN++;
  54.             } else {
  55.                 newWord += currentLetter;
  56.             }
  57.  
  58.             if (secretWord.length === 3) {
  59.                 resultWord += newWord + " ";
  60.                 newWord = "";
  61.                 counterC = 0;
  62.                 counterO = 0;
  63.                 counterN = 0;
  64.                 secretWord = "";
  65.             }
  66.         } else {
  67.             command = input[index];
  68.             index++;
  69.             continue;
  70.         }
  71.  
  72.         command = input[index];
  73.         index++;
  74.     }
  75.  
  76.     console.log(resultWord);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment