Advertisement
Silviya7

9.Dictionary

Mar 21st, 2024
441
0
117 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.    
  3.     let ObjectProduct='';
  4.  
  5.     let ArrProducts={};
  6.     for (const product of input) {
  7.        
  8.          ObjectProduct= JSON.parse(product);// in Object
  9.          let entries= Object.entries(ObjectProduct);
  10.  
  11.          let NewObject={Term:'', Definition:'' };
  12.          for (let[key,value] of entries) {          
  13.             ArrProducts[key]=value;  
  14.          
  15.          }
  16.          
  17.     }
  18.  
  19.  
  20.     let FinalArr=Object.entries(ArrProducts).sort((a, b) => a[0].localeCompare(b[0]));  
  21.     for (const [key,value] of FinalArr) {
  22.     console.log(`Term: ${key} => Definition: ${value}` );
  23.            
  24.         }
  25.     }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement