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