Mitfreex

02. biscuits midex jsf 06032021

Mar 7th, 2021
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bisc(input) {
  2.  
  3.     let [biscuits, ...comands] = input;
  4.     biscuits = biscuits.split(', ');
  5.  
  6.     //console.log(biscuits + '\n' + comands);
  7.  
  8.     for (let current of comands) {
  9.  
  10.         let [currentComand, typeBis, index] = current.split(' ');
  11.  
  12.         if (currentComand == 'Update-Any') {
  13.  
  14.             if (biscuits.includes(typeBis)) {
  15.  
  16.                 biscuits = biscuits
  17.                     .map(x => (x == typeBis) ? x = 'Outofstock' : x = x);
  18.             }
  19.  
  20.         } else if (currentComand == 'Remove') {
  21.             if (index < biscuits.length) {
  22.                 biscuits.splice(index, 1, typeBis);
  23.             }
  24.  
  25.         } else if (currentComand == 'Update-Last') {
  26.  
  27.             biscuits.splice(-1);
  28.             biscuits.push(typeBis);
  29.  
  30.         } else if (currentComand == 'Rearrange') {
  31.  
  32.             if (biscuits.includes(typeBis)) {
  33.  
  34.                 biscuits = biscuits.filter(word => word !== typeBis);
  35.                 biscuits.push(typeBis);
  36.             }
  37.  
  38.  
  39.  
  40.         } else if (currentComand == 'Eat') {
  41.             break;
  42.         }
  43.  
  44.  
  45.     }
  46.  
  47.     biscuits = biscuits.filter(word => word !== 'Outofstock').join(' ');
  48.  
  49.  
  50.     console.log(biscuits);
  51.  
  52. }
  53.  
  54. bisc([
  55.     "Vanilla, Chocolate, Raspberry, Strawberry, Walnuts, WhiteChocolate, Ordinary, Vegan",
  56.     "Update-Any Chocolate",
  57.     "Remove BBB 3",
  58.     "Update-Last Healthy",
  59.     "Eat"
  60. ]);
  61.  
  62. bisc([
  63.     "Vanilla, Chocolate, Raspberry, Strawberry, Walnuts, WhiteChocolate, Ordinary, Vegan",
  64.     "Update-Any Chocolate",
  65.     "Remove BBB 3",
  66.     "Rearrange Walnuts",
  67.     "Eat"
  68. ]);
Advertisement
Add Comment
Please, Sign In to add comment