Advertisement
dilyana2001

Untitled

Jun 21st, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function arrayManipulations(arr) {
  2.     let array = arr.shift().split(' ')
  3.     arr.forEach(line => {
  4.         let [command, ...args] = line.split(' ');
  5.         if (command === 'Add') {
  6.             array.push(args[0]);
  7.         } else if (command === 'Remove') {
  8.             if (array.indexOf(args[0]) !== -1) {
  9.                 array.splice(array.indexOf(args[0]), 1);
  10.             }
  11.         } else if (command === 'RemoveAt') {
  12.             array.splice(args[0], 1)
  13.         } else if (command === 'Insert') {
  14.             array.splice(args[1], 0, args[0]);
  15.         }
  16.     })
  17.     return array.map(Number).join(' ');
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement