Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let text = '';
- for (let i = 0; i < input.length; i++) {
- let [command, value] = input[i].split(' ');
- if (command === 'End') {
- break;
- }
- if (command === 'Add') {
- text += value;
- }
- if (command === 'Upgrade') {
- let ascii = value.charCodeAt(0);
- let char = String.fromCharCode(ascii + 1);
- let arr = text.split('');
- for (let i = 0; i < arr.length; i++) {
- if (arr[i] === value) {
- arr[i] = char;
- }
- }
- text = arr.join('');
- }
- if (command === 'Print') {
- console.log(text);
- }
- if (command === 'Index') {
- let indeces = [];
- for (let i = 0; i < text.length; i++) {
- if (text[i] === value) {
- indeces.push(i);
- }
- }
- console.log(indeces.join(' '));
- }
- if (command === 'Remove') {
- let arr = text.split(value);
- text = arr.join('');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement