georgiev955

03. Stream Of Letters

Mar 30th, 2023
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let command;
  3.   let index = 0;
  4.   let word = "";
  5.   let result = "";
  6.   let cCounter = 0;
  7.   let oCounter = 0;
  8.   let nCounter = 0;
  9.   while ((command = input[index]) !== "End") {
  10.     if (
  11.       (command.charCodeAt(0) >= 65 && command.charCodeAt(0) <= 90) ||
  12.       (command.charCodeAt(0) >= 97 && command.charCodeAt(0) <= 122)
  13.     ) {
  14.       if (command !== "c" && command !== "o" && command !== "n") {
  15.         word += command;
  16.       } else {
  17.         if (command === "c" && cCounter === 0) {
  18.           cCounter++;
  19.         } else if (command === "c" && cCounter !== 0) {
  20.           word += "c";
  21.         }
  22.         if (command === "o" && oCounter === 0) {
  23.           oCounter++;
  24.         } else if (command === "o" && oCounter !== 0) {
  25.           word += "o";
  26.         }
  27.         if (command === "n" && nCounter === 0) {
  28.           nCounter++;
  29.         } else if (command === "n" && nCounter !== 0) {
  30.           word += "n";
  31.         }
  32.       }
  33.  
  34.       if (cCounter + oCounter + nCounter === 3) {
  35.         result += word + " ";
  36.         cCounter = 0;
  37.         oCounter = 0;
  38.         nCounter = 0;
  39.         word = "";
  40.       }
  41.     }
  42.     index++;
  43.   }
  44.   console.log(result);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment