Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let items = input.shift().split("|");
- let budget = Number(input.shift());
- // console.log(items);
- let newPrice = 0;
- let totalNewPrice = 0;
- let profit = 0;
- let totalPrices = 0;
- let newPricesArr = [];
- for (let i = 0; i < items.length; i++) {
- let [products, prices] = items[i].split("->");
- // console.log(products);
- // console.log(prices);
- let currentPrice = Number(prices);
- // budget -= currentPrice;
- if (currentPrice > budget) {
- break;
- }
- let maxPrice = 0;
- let newPrice = 0;
- if (products === "Clothes") {
- maxPrice = 50.0;
- if (currentPrice <= maxPrice) {
- budget -= currentPrice;
- newPrice = Number(prices) + currentPrice * 0.4;
- totalNewPrice += newPrice;
- totalPrices += Number(prices);
- }
- } else if (products === "Shoes") {
- maxPrice = 35.0;
- if (currentPrice <= maxPrice) {
- budget -= currentPrice;
- newPrice = Number(prices) + currentPrice * 0.4;
- totalNewPrice += newPrice;
- totalPrices += Number(prices);
- }
- } else if (products === "Accessories") {
- maxPrice = 20.5;
- if (currentPrice <= maxPrice) {
- budget -= currentPrice;
- newPrice = Number(prices) + currentPrice * 0.4;
- totalNewPrice += newPrice;
- totalPrices += Number(prices);
- }
- }
- // console.log(budget);
- // console.log(newPrice);
- newPricesArr.push(newPrice.toFixed(2));
- profit = totalNewPrice - totalPrices;
- // console.log(profit.toFixed(2));
- }
- console.log(newPricesArr.join(' '));
- console.log(`Profit: ${profit.toFixed(2)}`);
- newPricesArr.map(Number);
- let sum = newPricesArr.reduce((a, b) => a + b, 0);
- sum = totalNewPrice + budget;
- if(sum > 150){
- console.log("Hello, France!");
- } else {
- console.log('Time to go.');
- }
- }
Add Comment
Please, Sign In to add comment