Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(commands) {
- let i,
- numbres = commands.shift().split(' '),
- temp,
- index;
- for (i = 0; i < commands.length; i += 1) {
- temp = commands[i].split(' ');
- switch (temp[0]) {
- case 'Add':
- numbres.push(temp[1]);
- break;
- case 'Remove':
- // index = numbres.indexOf(temp[1])
- // numbres.splice(index, 1);
- numbres=numbres.filter(x=>x!==temp[1]);
- break;
- case 'RemoveAt':
- index = Number(temp[1]);
- numbres.splice(index, 1);
- break;
- case 'Insert':
- index = Number(temp[2]);
- numbres.splice(index, 0, temp[1]);
- break;
- }
- }
- console.log(numbres.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment