Advertisement
Liliana797979

viarno reshenie steam of letters1

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