-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpb-03-logistics.js
35 lines (32 loc) · 903 Bytes
/
pb-03-logistics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//PB-03. Logistics
function logistics(input) {
let cargo = Number(input[0]);
let priceBus = 200;
let priceTruck = 175;
let priceTrain = 120;
let bus = 0;
let truck = 0;
let train = 0;
let totalCargo = 0;
for (let i = 1; i <= cargo; i++) {
let num = Number(input[i]);
totalCargo += num;
if (num <= 3) {
bus += num;
} else if (num > 3 && num < 12) {
truck += num;
} else {
train += num;
}
}
console.log(
`${(
(bus * priceBus + truck * priceTruck + train * priceTrain) /
totalCargo
).toFixed(2)}`
);
console.log(`${((bus / totalCargo) * 100).toFixed(2)}%`);
console.log(`${((truck / totalCargo) * 100).toFixed(2)}%`);
console.log(`${((train / totalCargo) * 100).toFixed(2)}%`);
}
logistics(["4", "1", "5", "16", "3"]);