viktoriq_23

04. Store Catalogue - JS-Advanced / JS-Fundamentals

Jan 27th, 2021
161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     arr.sort();
  3.  
  4.     let lastLetter;
  5.     while(arr.length!=0){
  6.         if(arr[0][0]!=lastLetter){
  7.             lastLetter = arr[0][0];
  8.             console.log(lastLetter);
  9.         }
  10.         let [product, price]= arr.shift().split(' : ');
  11.         console.log(`  ${product}: ${price}`);
  12.     }
  13. }
RAW Paste Data