Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addAndRemove(arr) {
- let result = []
- for (let i = 0; i < arr.length; i++) {
- if (arr[i] === 'add') {
- result.push(i + 1)
- } else if (arr[i] === 'remove') {
- result.pop();
- }
- }
- if (result.length > 0) {
- console.log(result.join(' '))
- } else {
- console.log(`Empty`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement