Advertisement
dilyana2001

Add and Remove

Jun 6th, 2021 (edited)
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addAndRemove(arr) {
  2.     let result = []
  3.     for (let i = 0; i < arr.length; i++) {
  4.         if (arr[i] === 'add') {
  5.             result.push(i + 1)
  6.         } else if (arr[i] === 'remove') {
  7.             result.pop();
  8.         }
  9.     }
  10.     if (result.length > 0) {
  11.         console.log(result.join(' '))
  12.     } else {
  13.         console.log(`Empty`)
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement