Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function catalogue(args) {
- const listKeys = [];
- args.sort((a, b) => a.localeCompare(b));
- args.forEach((element) => {
- const key = element.charAt(0);
- const alphaObj = {};
- alphaObj.key = key;
- alphaObj.value = [];
- const dub = listKeys.filter((el) => el.key === key).length;
- if (dub === 0) {
- listKeys.push(alphaObj);
- }
- listKeys.forEach((el) => {
- if (el.key === key) {
- el.value.push(element);
- }
- });
- });
- listKeys.forEach((element) => {
- const productName = element.key;
- const productPrice = element.value;
- console.log(`${productName}`);
- productPrice.forEach((el) => {
- const [name, price] = el.split(':');
- name.trimEnd();
- console.log(` ${name.trimEnd()}:${price}`);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement