Advertisement
Guest User

sss

a guest
May 9th, 2020
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input = []) {
  2.  
  3.     let newArr = [];
  4.     let num = 0;
  5.     for (let i = 0; i <= input.length; i++) {
  6.  
  7.         if (input[i] === 'add') {
  8.             num++;
  9.             newArr.push(num);
  10.         }
  11.  
  12.         else if (input[i] === 'remove') {
  13.             num++;
  14.             newArr.pop(i)
  15.         }
  16.  
  17.         else if (input[i] === 'remove') {
  18.             console.log('Emty');
  19.             break;
  20.         }
  21.  
  22. }
  23.  
  24. console.log(newArr.join(' '));
  25. }
  26.  
  27. solve(['remove', 'remove', 'remove'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement