Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let output = [];
- for (const line of input) {
- let[product, price] = line.split(' : ');
- let singleObj = {product,price};
- output.push(singleObj);
- }
- output.sort((a,b)=>a.product.localeCompare(b.product));
- let firstLetter = output.map(item=>{
- return item.product[0];
- });
- let uniqFirstLetter = [];
- for (const letter of firstLetter) {
- if(!uniqFirstLetter.includes(letter)){
- uniqFirstLetter.push(letter);
- }
- }
- for (const object of output) {
- let first = object.product[0];
- if(first === uniqFirstLetter[0]){
- console.log(uniqFirstLetter.shift());
- }
- console.log(` ${object.product}: ${object.price}`);
- }
- }
Add Comment
Please, Sign In to add comment