SHARE
TWEET

Untitled

marian74 May 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function easterGifts(data) {
  2.     let giftsList = data.shift().split(' ');
  3.     let commandAndGiftAndIndex = data.shift();
  4.  
  5.     while (commandAndGiftAndIndex !== 'No Money') {
  6.         let [command, gift, index] = commandAndGiftAndIndex.split(' ')
  7.         if (command === 'OutOfStock') {
  8.             gift
  9.             while (giftsList.includes(gift)) {
  10.                 let index = giftsList.indexOf(gift);
  11.                 giftsList[index] = 'None';
  12.                
  13.             }
  14.         } else if (command === 'Required') {
  15.             if (index < giftsList.length ) {
  16.                 giftsList.splice(index, 1, gift);
  17.             }
  18.         } else if (command === 'JustInCase') {
  19.            
  20.             giftsList.pop();
  21.             giftsList.push(gift);
  22.         }
  23.         commandAndGiftAndIndex = data.shift();
  24.     }
  25.     let line = [];
  26.     giftsList.forEach(e => {
  27.         if (e !== 'None') {
  28.         line.push(e)
  29.     }
  30.     });
  31.     console.log(line.join(' '))
  32.  
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top