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] === 'remove') {
- result.pop();
- } else if (arr[i] === 'add') {
- result.push(i + 1);
- }
- }
- if (result.length === 0) {
- console.log('Empty');
- } else {
- console.log(result.join(' '));
- }
- }
- addAndRemove(['add','add','remove','add','add']);
Advertisement
Add Comment
Please, Sign In to add comment