Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let list = arr.shift().split(' ').map(Number);
- for(let element of arr) {
- let temp = element.split(' ');
- let command = temp[0];
- let next = Number(temp[1]);
- if(command === "Add") {
- list.push(next);
- }
- else if(command === "Remove") {
- list.splice(list.indexOf(next), 1);
- }
- else if(command === "Replace") {
- let random = Number(temp[2]);
- list.splice(list.indexOf(next), 1, random);
- }
- else if(command === "Collapse") {
- let fix = list.filter(x => x >= next);
- list.splice(0, list.length);
- list.push(...fix);
- }
- else if(command === "Finish") {
- break;
- }
- }
- console.log(list.join(' '));
- }
- solve(["5 9 70 -56 9 9","Replace 9 10","Remove 9","Finish"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement