desito07

Hello, France

Jul 1st, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. function solve(input) {
  2. let items = input.shift().split("|");
  3. let budget = Number(input.shift());
  4. // console.log(items);
  5. let newPrice = 0;
  6. let totalNewPrice = 0;
  7. let profit = 0;
  8. let totalPrices = 0;
  9. let newPricesArr = [];
  10.  
  11. for (let i = 0; i < items.length; i++) {
  12. let [products, prices] = items[i].split("->");
  13. // console.log(products);
  14. // console.log(prices);
  15. let currentPrice = Number(prices);
  16. // budget -= currentPrice;
  17.  
  18. if (currentPrice > budget) {
  19. break;
  20. }
  21.  
  22. let maxPrice = 0;
  23. let newPrice = 0;
  24.  
  25. if (products === "Clothes") {
  26. maxPrice = 50.0;
  27. if (currentPrice <= maxPrice) {
  28. budget -= currentPrice;
  29. newPrice = Number(prices) + currentPrice * 0.4;
  30. totalNewPrice += newPrice;
  31. totalPrices += Number(prices);
  32. }
  33. } else if (products === "Shoes") {
  34. maxPrice = 35.0;
  35. if (currentPrice <= maxPrice) {
  36. budget -= currentPrice;
  37. newPrice = Number(prices) + currentPrice * 0.4;
  38. totalNewPrice += newPrice;
  39. totalPrices += Number(prices);
  40. }
  41. } else if (products === "Accessories") {
  42. maxPrice = 20.5;
  43. if (currentPrice <= maxPrice) {
  44. budget -= currentPrice;
  45. newPrice = Number(prices) + currentPrice * 0.4;
  46. totalNewPrice += newPrice;
  47. totalPrices += Number(prices);
  48. }
  49. }
  50.  
  51. // console.log(budget);
  52. // console.log(newPrice);
  53. newPricesArr.push(newPrice.toFixed(2));
  54. profit = totalNewPrice - totalPrices;
  55. // console.log(profit.toFixed(2));
  56. }
  57. console.log(newPricesArr.join(' '));
  58. console.log(`Profit: ${profit.toFixed(2)}`);
  59.  
  60. newPricesArr.map(Number);
  61. let sum = newPricesArr.reduce((a, b) => a + b, 0);
  62. sum = totalNewPrice + budget;
  63. if(sum > 150){
  64. console.log("Hello, France!");
  65. } else {
  66. console.log('Time to go.');
  67. }
  68. }
Add Comment
Please, Sign In to add comment