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