Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let arr = input.shift().split(' ').map(Number);
- for (let i = 0; i < input.length; i++) {
- let command = input[i].split(' ');
- //console.log(command)
- let word = command[0];
- if (word == 'Add') {
- let num1 = Number(command[1]);
- arr.push(num1);
- } else if (word == 'Remove') {
- let num2 = Number(command[1]);
- for (let j = 0; j < arr.length; j++) {
- if (arr[j] == num2) {
- arr.splice(j, 1);
- }
- }
- } else if (word == 'RemoveAt') {
- let num3 = Number(command[1]);
- arr.splice(num3, 1);
- } else if (word == 'Insert') {
- let num4 = Number(command[1]);
- let index = Number(command[2]);
- arr.splice(index, 0, num4);
- }
- }
- console.log(arr.join(' '));
- }
- solve(['4 19 2 53 6 43',
- 'Add 3',
- 'Remove 2',
- 'RemoveAt 1',
- 'Insert 8 3'
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement