Guest User

Untitled

a guest
Sep 30th, 2019
195
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function france(array) {
  2.  
  3.     let newArr = [];
  4.     let newPrice = 0;
  5.     let profit = 0;
  6.  
  7.     let budget = array.pop();
  8.     budget = Number(budget);
  9.  
  10.     let line = array.join(' ').split('->');
  11.     line = line.join(' ').split('|');
  12.     let word = line.join(' ').split(' ');
  13.  
  14.  
  15.     while (true) {
  16.         if (word[0] === undefined) {
  17.             break;
  18.         }
  19.  
  20.         let firstWord = word.shift();
  21.         let secondWord = word.shift();
  22.         secondWord = Number(secondWord);
  23.  
  24.         if (Number(secondWord) > budget) {
  25.             break;
  26.         }
  27.  
  28.         if (firstWord === 'Clothes' && secondWord > 50) {
  29.             continue;
  30.          }
  31.         if (firstWord === 'Shoes' && secondWord > 35) {
  32.             continue;
  33.         }
  34.         if (firstWord === 'Accessories' && secondWord > 20.5) {
  35.             continue;
  36.         } else {
  37.             budget -= secondWord;
  38.             newPrice = secondWord + (secondWord * 0.4)
  39.             newPrice = newPrice.toFixed(2)
  40.             profit += newPrice - secondWord;
  41.             newArr.push(newPrice)
  42.         }
  43.     }
  44.  
  45.     console.log(newArr.join(' '));
  46.     console.log(`Profit: ${profit.toFixed(2)}`);
  47.    
  48.    
  49.     let numberArr = newArr.map(Number);
  50.     let sum = numberArr.reduce((a, b) => a + b, 0)
  51.     sum = sum + budget;
  52.  
  53.     if (sum > 150) {
  54.         console.log('Hello, France!');
  55.     } else {
  56.         console.log('Time to go.');
  57.  
  58.     }
  59.  
  60. }
RAW Paste Data