Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addAndRemove0(arr) {
- 'use strict'
- let workArr = arr
- let outputArr = []
- let index = 0
- for (let i = 0; i < workArr.length; i++) {
- if (workArr[i] === 'add') {
- outputArr[index] = (i + 1)
- index++
- }
- else if (workArr[i] === 'remove') {
- if (index !== 0) {
- outputArr[index - 1] = undefined
- index--
- }
- else
- outputArr[0] = undefined
- }
- }
- let output = ''
- let lengthArray = 0
- while (outputArr[lengthArray] !== undefined) {
- lengthArray++
- }
- for (let i = 0; i < lengthArray; i++)
- output += outputArr[i] + ' '
- if (lengthArray === 0)
- console.log('Empty')
- else
- console.log(output)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement