Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function storeCatalogue(input) {
- const map = new Map();
- input.forEach((line) => {
- const tokens = line.split(' : ');
- const [product, price] = tokens;
- map.set(product, price);
- });
- const initials = new Set();
- Array.from(map.keys()).forEach((k) => initials.add(k[0]));
- Array.from(initials.keys()).sort().forEach((char) => {
- console.log(char);
- Array.from(map.keys()).sort().forEach((product) => {
- if (product.startsWith(char)) {
- console.log(` ${product}: ${map.get(product)}`);
- }
- });
- });
- }
Add Comment
Please, Sign In to add comment