Advertisement
Guest User

System Register

a guest
Nov 6th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function systemRegister(array) {
  2.     let systems=new Map();
  3.  
  4.     for(let element of array){
  5.         let [elementName,componentName,subcomponentName]=element.split(` | `);
  6.         if(!systems.has(elementName)){
  7.             systems.set(elementName,{});
  8.             systems.get(elementName)[componentName]=[];
  9.         }else{
  10.             if(!systems.get(elementName)[componentName]){
  11.                 systems.get(elementName)[componentName]=[];
  12.             }
  13.         }
  14.         systems.get(elementName)[componentName].push(subcomponentName);
  15.     }
  16.  
  17.     let result=Array.from(systems);
  18.  
  19.     result.sort((element1,element2)=>{
  20.         return Object.keys(element2[1]).length-Object.keys(element1[1]).length || element1[0].toLowerCase().localeCompare(element2[0].toLowerCase())
  21.     })
  22.  
  23.         Object.keys(result[0][1]).sort((comp1,comp2)=>{
  24.  
  25.         return Object.values(result[0][1][comp2]).length-Object.values(result[0][1][comp1]).length
  26.     })
  27.  
  28.     for(let element of result){
  29.         console.log(element[0])
  30.         for(let component in element[1]){
  31.             console.log(`|||${component}`);
  32.             for(let subcomponent of element[1][component]){
  33.                 console.log(`||||||${subcomponent}`);
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement