Advertisement
Guest User

Untitled

a guest
Jul 28th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let text = '';
  3.     for (let i = 0; i < input.length; i++) {
  4.         let [command, value] = input[i].split(' ');
  5.  
  6.         if (command === 'End') {
  7.             break;
  8.         }
  9.         if (command === 'Add') {
  10.             text += value;
  11.         }
  12.         if (command === 'Upgrade') {
  13.             let ascii = value.charCodeAt(0);
  14.             let char = String.fromCharCode(ascii + 1);
  15.             let arr = text.split('');
  16.             for (let i = 0; i < arr.length; i++) {
  17.                 if (arr[i] === value) {
  18.                     arr[i] = char;
  19.                 }
  20.             }
  21.             text = arr.join('');
  22.         }
  23.         if (command === 'Print') {
  24.             console.log(text);
  25.         }
  26.         if (command === 'Index') {
  27.             let indeces = [];
  28.  
  29.             for (let i = 0; i < text.length; i++) {
  30.                 if (text[i] === value) {
  31.                     indeces.push(i);
  32.                 }
  33.             }
  34.             console.log(indeces.join(' '));
  35.         }
  36.         if (command === 'Remove') {
  37.             let arr = text.split(value);
  38.             text = arr.join('');
  39.  
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement