Guest User

Catalogue

a guest
Oct 11th, 2018
177
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function catalogue(input) {
  2.  
  3.     let products = [];
  4.  
  5.     for (let i = 0; i < input.length; i++) {
  6.         products.push(input[i].split(" :")
  7.             .join(":"));
  8.     }
  9.  
  10.     products.sort((a, b) => a.toLowerCase()
  11.         .localeCompare(b.toLowerCase()));
  12.  
  13.     let firstLetter = "";
  14.     for (let product of products) {
  15.         if (firstLetter !== product.charAt(0)) {
  16.             firstLetter = product.charAt(0);
  17.             console.log(firstLetter);
  18.         }
  19.  
  20.         console.log("  " + product);
  21.     }
  22. }
RAW Paste Data