Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var input = prompt ("Введите");
  2. var output="";
  3. var quantity = 1;
  4. for (var i = 0; i < input.length; i++)
  5. {
  6.     if (i !== 0)
  7.     {
  8.         if (input[i-1] === input[i])
  9.         {
  10.             quantity++;
  11.             if (i === input.length-1)
  12.             {
  13.                 output+=input[i]+quantity;
  14.                 quantity = 1;
  15.             }
  16.         }
  17.         else
  18.         {
  19.             if(quantity !== 1)
  20.             {
  21.                 output += input[i-1]+quantity;
  22.                 quantity = 1;
  23.             }
  24.             else
  25.                 output += input[i-1];
  26.             if (i === input.length-1)
  27.                 output += input[i];
  28.         }
  29.     }
  30.     else
  31.     {
  32.         if (i === input.length - 1)
  33.         {
  34.             output = input[i];
  35.             break;
  36.         }
  37.         else
  38.             continue;
  39.     }
  40. }
  41. alert(output);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement