Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bisc(input) {
- let [biscuits, ...comands] = input;
- biscuits = biscuits.split(', ');
- //console.log(biscuits + '\n' + comands);
- for (let current of comands) {
- let [currentComand, typeBis, index] = current.split(' ');
- if (currentComand == 'Update-Any') {
- if (biscuits.includes(typeBis)) {
- biscuits = biscuits
- .map(x => (x == typeBis) ? x = 'Outofstock' : x = x);
- }
- } else if (currentComand == 'Remove') {
- if (index < biscuits.length) {
- biscuits.splice(index, 1, typeBis);
- }
- } else if (currentComand == 'Update-Last') {
- biscuits.splice(-1);
- biscuits.push(typeBis);
- } else if (currentComand == 'Rearrange') {
- if (biscuits.includes(typeBis)) {
- biscuits = biscuits.filter(word => word !== typeBis);
- biscuits.push(typeBis);
- }
- } else if (currentComand == 'Eat') {
- break;
- }
- }
- biscuits = biscuits.filter(word => word !== 'Outofstock').join(' ');
- console.log(biscuits);
- }
- bisc([
- "Vanilla, Chocolate, Raspberry, Strawberry, Walnuts, WhiteChocolate, Ordinary, Vegan",
- "Update-Any Chocolate",
- "Remove BBB 3",
- "Update-Last Healthy",
- "Eat"
- ]);
- bisc([
- "Vanilla, Chocolate, Raspberry, Strawberry, Walnuts, WhiteChocolate, Ordinary, Vegan",
- "Update-Any Chocolate",
- "Remove BBB 3",
- "Rearrange Walnuts",
- "Eat"
- ]);
Advertisement
Add Comment
Please, Sign In to add comment