Advertisement
Todorov_Stanimir

03. Rage Quit с резултат 100/100, но локално 3-ти тест гърми

Jun 18th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pageQuit1(input) {
  2.     let inputArray = String(input[0]).split('');
  3.     let currArray = [];
  4.     let currArrayCounter = [];
  5.     let currentString = '';
  6.     let newIndex = 0;
  7.     let count = '';
  8.     for (let index = 0; index < inputArray.length; index++) {
  9.         if (48 <= inputArray[index].charCodeAt() && inputArray[index].charCodeAt() <= 57) {
  10.             [newIndex, count] = startNextString(inputArray, index);
  11.         } else {
  12.             currentString += inputArray[index];
  13.             newIndex = index;
  14.         }
  15.         if (newIndex != index || newIndex === inputArray.length - 1) {
  16.             currentString = currentString.toUpperCase();
  17.             currArray.push(currentString);
  18.             currArrayCounter.push(Number(count));
  19.             currentString = '';
  20.             count = ''
  21.             if (newIndex !== inputArray.length - 1) {
  22.                 index = newIndex - 1;
  23.             } else {
  24.                 break
  25.             }
  26.         }
  27.     }
  28.  
  29.     for (let i = 0; i < currArray.length; i++) {
  30.      
  31.         currArray[i] = currArray[i].repeat(currArrayCounter[i]);
  32.     }
  33.     let uniqueSymbols = [...new Set(currArray.join(''))].length;
  34.  
  35.     console.log(`Unique symbols used: ${uniqueSymbols}`);
  36.     console.log(currArray.join(''));
  37.  
  38.  
  39.  
  40.     function startNextString(inputArray, index) {
  41.         newIndex = index;
  42.         let lastPart = ''
  43.         while (48 <= inputArray[newIndex].charCodeAt() && inputArray[newIndex].charCodeAt() <= 57) {
  44.             lastPart += inputArray[newIndex];
  45.             newIndex++;
  46.             if (newIndex === inputArray.length) {
  47.                 newIndex--;
  48.                 break;
  49.             }
  50.         }
  51.         return [newIndex, lastPart];
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement