Todorov_Stanimir

03. Rage Quit с резултат 90/100 и гърмящ трети нулев тест

Jun 18th, 2019
178
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.     let output = '';
  29.     for (let i = 0; i < currArray.length; i++) {
  30.         for (let y = 0; y < currArrayCounter[i]; y++) {
  31.             output += currArray[i];
  32.         }
  33.     }
  34.     let uniqueSymbols = [...new Set(currArray.join(''))].length;
  35.  
  36.     console.log(`Unique symbols used: ${uniqueSymbols}`);
  37.     console.log(output);
  38.  
  39.  
  40.  
  41.     function startNextString(inputArray, index) {
  42.         newIndex = index;
  43.         let lastPart = ''
  44.         while (48 <= inputArray[newIndex].charCodeAt() && inputArray[newIndex].charCodeAt() <= 57) {
  45.             lastPart += inputArray[newIndex];
  46.             newIndex++;
  47.             if (newIndex === inputArray.length) {
  48.                 newIndex--;
  49.                 break;
  50.             }
  51.         }
  52.         return [newIndex, lastPart];
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment