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