Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let command;
- let index = 0;
- let word = "";
- let result = "";
- let cCounter = 0;
- let oCounter = 0;
- let nCounter = 0;
- while ((command = input[index]) !== "End") {
- if (
- (command.charCodeAt(0) >= 65 && command.charCodeAt(0) <= 90) ||
- (command.charCodeAt(0) >= 97 && command.charCodeAt(0) <= 122)
- ) {
- if (command !== "c" && command !== "o" && command !== "n") {
- word += command;
- } else {
- if (command === "c" && cCounter === 0) {
- cCounter++;
- } else if (command === "c" && cCounter !== 0) {
- word += "c";
- }
- if (command === "o" && oCounter === 0) {
- oCounter++;
- } else if (command === "o" && oCounter !== 0) {
- word += "o";
- }
- if (command === "n" && nCounter === 0) {
- nCounter++;
- } else if (command === "n" && nCounter !== 0) {
- word += "n";
- }
- }
- if (cCounter + oCounter + nCounter === 3) {
- result += word + " ";
- cCounter = 0;
- oCounter = 0;
- nCounter = 0;
- word = "";
- }
- }
- index++;
- }
- console.log(result);
- }
Advertisement
Add Comment
Please, Sign In to add comment