Advertisement
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());
- let money = budget;
- let boughtItems = [];
- let increased = []
- let newBudget = 0;
- let profit = 0;
- for (const line of items) {
- let [type, price] = line.split('->');
- let currentPrice = Number(price);
- switch (type){
- case 'Clothes':
- if (currentPrice <= 50.00 && currentPrice < money) {
- boughtItems.push(currentPrice);
- money -= currentPrice;
- }
- break;
- case 'Shoes':
- if (currentPrice <= 35.00 && currentPrice < money) {
- boughtItems.push(currentPrice);
- money -= currentPrice;
- }
- break;
- case 'Accessories':
- if (currentPrice <= 20.50 && currentPrice < money) {
- boughtItems.push(currentPrice);
- money -= currentPrice;
- }
- break;
- }
- }
- //increased = boughtItems.map(x => Number((x * 1.4).toFixed(2)))
- let sumOfBoughtItems = 0;
- for (let price of boughtItems){
- let increasedPrice = Number((price + (price * 0.4)).toFixed(2));
- increased.push(increasedPrice);
- profit += Number(increasedPrice) - price;
- sumOfBoughtItems += increasedPrice;
- }
- sumOfBoughtItems += money
- console.log(increased.join(' '));
- console.log(`Profit: ${profit.toFixed(2)}`);
- if (sumOfBoughtItems >= 150) {
- console.log('Hello, France!');
- } else {
- console.log('Time to go.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement