nikolayneykov

Untitled

Feb 24th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(commands) {
  2.     let i,
  3.         numbres = commands.shift().split(' '),
  4.         temp,
  5.         index;
  6.  
  7.     for (i = 0; i < commands.length; i += 1) {
  8.         temp = commands[i].split(' ');
  9.         switch (temp[0]) {
  10.             case 'Add':
  11.                 numbres.push(temp[1]);
  12.                 break;
  13.  
  14.             case 'Remove':
  15.                 // index = numbres.indexOf(temp[1])
  16.                 // numbres.splice(index, 1);
  17.                 numbres=numbres.filter(x=>x!==temp[1]);
  18.                 break;
  19.  
  20.             case 'RemoveAt':
  21.                 index = Number(temp[1]);
  22.                 numbres.splice(index, 1);
  23.                 break;
  24.  
  25.             case 'Insert':
  26.                 index = Number(temp[2]);
  27.                 numbres.splice(index, 0, temp[1]);
  28.                 break;
  29.         }
  30.     }
  31.     console.log(numbres.join(' '));
  32. }
Advertisement
Add Comment
Please, Sign In to add comment