Militsa

10. Add / Remove Elements

Dec 25th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myFunction(text) {
  2.     let array=[]
  3.  
  4.     for (let i=0; i<text.length; i++){
  5.         let tempArr = text[i].split(' ')
  6.         command=tempArr[0]
  7.         value=tempArr[1]
  8.  
  9.         if(command=="add"){
  10.             array.push(value)
  11.         }
  12.         if(command=="remove"){
  13.             array.splice(value, 1)
  14.         }
  15.     }
  16.  
  17.     for(let j=0; j<array.length; j++){
  18.         console.log(array[j])
  19.     }
  20. }
  21.  
  22. //myFunction(['add 3', 'add 5', 'add 7']);
Add Comment
Please, Sign In to add comment