Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createStoreCatalogue(input) {
- let catalogue = {};
- input.forEach(el => {
- let [product, price] = el.split(' : ');
- if (!catalogue.hasOwnProperty(product[0])) {
- catalogue[product[0]] = {};
- }
- catalogue[product[0]][product] = Number(price);
- });
- let sortedCatalogue = Object.entries(catalogue).sort((a, b) => a[0].localeCompare(b[0]));
- sortedCatalogue.forEach(el => {
- let sortedProductsData = Object.entries(el[1]).sort((a, b) => a[0].localeCompare(b[0])).map((a) => `${a[0]}: ${a[1]}`);
- console.log(el[0]);
- sortedProductsData.forEach(a => console.log(` ${a}`))
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement