Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function catalogue(input) {
- let catalog = [];
- for (let i = 0; i < input.length; i ++) {
- let currItem = input[i].split(" : ");
- let newItem = {};
- newItem.initial = currItem[0][0];
- newItem.productName = currItem[0];
- newItem.productPrice = currItem[1];
- catalog.push(newItem);
- }
- catalog.sort((a, b) => {
- if (a.productName > b.productName) {
- return 1
- } else {
- return -1
- }
- });
- let initList = [];
- for (let item in catalog) {
- if (initList.includes(catalog[item].initial)) {
- console.log(` ${catalog[item].productName}: ${catalog[item].productPrice}`);
- } else {
- console.log(`${catalog[item].initial}`);
- console.log(` ${catalog[item].productName}: ${catalog[item].productPrice}`);
- initList.push(catalog[item].initial);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement