Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let index = 0;
- let resultWord = "";
- let secretWord = "";
- let newWord = "";
- let counterC = 0;
- let counterO = 0;
- let counterN = 0;
- let latinLetters = [
- "a",
- "b",
- "c",
- "d",
- "e",
- "f",
- "g",
- "h",
- "i",
- "j",
- "k",
- "l",
- "m",
- "n",
- "o",
- "p",
- "q",
- "r",
- "s",
- "t",
- "u",
- "v",
- "w",
- "x",
- "y",
- "z",
- ];
- let command = input[index];
- index++;
- while (command !== "End") {
- let currentLetter = command;
- if (latinLetters.includes(currentLetter.toLowerCase())) {
- if (currentLetter.toLowerCase() === "c" && counterC === 0) {
- secretWord += currentLetter;
- counterC++;
- } else if (currentLetter.toLowerCase() === "o" && counterO === 0) {
- secretWord += currentLetter;
- counterO++;
- } else if (currentLetter.toLowerCase() === "n" && counterN === 0) {
- secretWord += currentLetter;
- counterN++;
- } else {
- newWord += currentLetter;
- }
- if (secretWord.length === 3) {
- resultWord += newWord + " ";
- newWord = "";
- counterC = 0;
- counterO = 0;
- counterN = 0;
- secretWord = "";
- }
- } else {
- command = input[index];
- index++;
- continue;
- }
- command = input[index];
- index++;
- }
- console.log(resultWord);
- }
Advertisement
Add Comment
Please, Sign In to add comment