Advertisement
Guest User

Hello,France

a guest
Apr 21st, 2019
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1.  
  2. function solve(arr, budget) {
  3.  
  4. let collectionOfItems = arr.split();
  5. let maxPriceClothes = 50;
  6. let maxPriceShoes = 35;
  7. let maxPriceAccessories = 20.50;
  8. let curr = [];
  9. let indcreased = [];
  10. let profit = 0;
  11.  
  12. for (let i = 0; i < collectionOfItems.length; i++) {
  13. let splited = collectionOfItems[i].split(/->/);
  14.  
  15. let currentItem = splited.shift();
  16. let currentPrice = Number(splited.shift());
  17. if (currentPrice > budget) {
  18. continue;
  19. }
  20. if (currentItem == 'Clothes' && !(currentPrice > maxPriceClothes)) {
  21. budget -= currentPrice;
  22. curr.push(currentPrice);
  23. }
  24. else if (currentItem == 'Shoes' && !(currentPrice > maxPriceShoes)) {
  25. budget -= currentPrice;
  26. curr.push(currentPrice);
  27. }
  28. else if (currentItem == 'Accessories' && !(currentPrice > maxPriceAccessories)) {
  29. budget -= currentPrice;
  30. curr.push(currentPrice);
  31. }
  32. if (isNaN(currentPrice)) {
  33. break;
  34. }
  35.  
  36. }
  37. let total = 0;
  38. for (const element of curr) {
  39. let increasedPrice = Number(element + (element * 0.4)).toFixed(2);
  40. indcreased.push(increasedPrice);
  41. profit += Number(increasedPrice) - element;
  42. total += +increasedPrice;
  43. }
  44. total += budget;
  45.  
  46. console.log(indcreased.join(' '));
  47. console.log(profit.toFixed(2));
  48. if (total >= 150) {
  49. console.log('Hello, France!');
  50.  
  51. }
  52. else {
  53. console.log('Time to go.');
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement