Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function autoEngineeringCompany(input) {
- let producedCars = {};
- input.forEach(element => {
- let [carBrand, carModel, producedQuantityCars] = element.split(' | ');
- producedQuantityCars = Number(producedQuantityCars);
- if (!producedCars[carBrand]) {
- producedCars[carBrand] = {};
- producedCars[carBrand][carModel] = producedQuantityCars;
- } else {
- !producedCars[carBrand][carModel]
- ? producedCars[carBrand][carModel] = producedQuantityCars
- : producedCars[carBrand][carModel] += producedQuantityCars
- }
- });
- Object.entries(producedCars).forEach(carBrand => {
- console.log(carBrand[0]);
- Object.entries(carBrand[1]).forEach(carModel => console.log(`###${carModel[0]} -> ${carModel[1]}`))
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement