Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- const result = [];
- arr.forEach((_, index) => {
- if (arr[index] === 'add') {
- result[index] = index + 1;
- } else if (arr[index] === 'remove') {
- result.pop();
- }
- });
- if (result.length <= 0) {
- console.log('Empty');
- }
- result.map((el) => el !== undefined && console.log(el));
- }
Advertisement
Add Comment
Please, Sign In to add comment