Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addAndRemoveElements(arr) {
  2.     let result = [];
  3.     for (let i = 0; i < arr.length; i++) {
  4.         if (arr[i] === 'add') {
  5.             result[i] = i + 1;
  6.         } else if (arr[i] === 'remove'){
  7.             result.splice(i - 1, 1)
  8.         }
  9.     }
  10.     if (result.length <= 0) {
  11.         console.log('Empty');
  12.     }
  13.     for (let i = 0; i < result.length; i++) {
  14.         if (result[i] === undefined || result[i] == '') {
  15.         } else {
  16.             console.log(result[i]);
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement