Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Logistics(input) {
- let cargoCount = Number(input[0]);
- let bus = 0.0;
- let truck = 0.0;
- let train = 0.0;
- let totalCargo = 0.0;
- for (let i = 1; i <= cargoCount; i++) {
- let cargo = Number(input[i]);
- if (cargo < 4) {
- bus += cargo;
- } else if (cargo < 12) {
- truck += cargo;
- } else {
- train += cargo;
- }
- totalCargo += cargo;
- }
- let average = (bus * 200 + truck * 175 + train * 120) / totalCargo;
- console.log(average.toFixed(2));
- console.log(`${(bus / totalCargo * 100).toFixed(2)}%`);
- console.log(`${(truck / totalCargo * 100).toFixed(2)}%`);
- console.log(`${(train / totalCargo * 100).toFixed(2)}%`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement