Advertisement
Liliana797979

viarno reshenie steam of letters

Feb 13th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.      
  3. function streamOfLetters(input) {
  4.     index = 0;
  5.     let command = input[index++];
  6.     let word = "";
  7.     let phrase = "";
  8.     countC = 0;
  9.     countN = 0;
  10.     countO = 0;
  11.  
  12.     while (command !== "End") {
  13.         let currentLetter = command;
  14.  
  15.         if ((currentLetter >= "A" && currentLetter <= "Z") || (currentLetter >= "a" && currentLetter <= "z")) {
  16.  
  17.             if (currentLetter === "c" && countC < 1) {
  18.                 countC++;
  19.             } else if (currentLetter === "o" && countO < 1) {
  20.                 countO++;
  21.             } else if (currentLetter === "n" && countN < 1) {
  22.                 countN++;
  23.             } else {
  24.                 word += currentLetter;
  25.             }
  26.  
  27.             if (countC === 1 && countN === 1 && countO === 1) {
  28.                 phrase += word + " ";
  29.                 word = "";
  30.                 countC = 0;
  31.                 countN = 0;
  32.                 countO = 0;
  33.             }
  34.  
  35.         }
  36.         command = input[index++];
  37.     }
  38.     console.log(phrase);
  39. }
  40.  
  41. streamOfLetters(["H", "n", "e", "l", "l", "o", "o", "c", "t", "c", "h", "o", "e", "r", "e", "n", "e", "End"]);
  42. streamOfLetters(['%', '!', 'c', '^', 'B', '`', 'o', '%', 'o', 'o', 'M', ')', '{', 'n', '\\', 'A', 'D', 'End']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement