Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solveCurrentProblem(input){
- let map = new Map();
- for(let productInfo of input){
- let [brand, model, quantity] = productInfo.split(/\s+\|\s+/);
- if(map.has(brand) === false){
- map.set(brand, new Map());
- }
- if(map.get(brand).has(model) === false){
- map.get(brand).set(model, 0);
- }
- map.get(brand).set(model, map.get(brand).get(model) + +quantity);
- }
- Array.from(map.keys()).forEach(brand => {
- console.log(brand);
- Array.from(map.get(brand)).forEach(model => {
- console.log(`###${model.join(" -> ")}`);
- })
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement