Advertisement
EntropyStarRover

06. Make a Dictionary

Jun 27th, 2019
144
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dictionary(input){
  2. let dictionary={}
  3.    let parsedItems=input.map(JSON.parse);
  4.  
  5.  
  6.    parsedItems.forEach(item => {
  7.        let tuple=Object.entries(item);
  8.        let term=tuple[0][0];
  9.        let definition=tuple[0][1];
  10.  
  11.        dictionary[term]=definition;
  12.    });
  13.  
  14.    let sortedItemd=Object.entries(dictionary)
  15.    .sort((a,b)=>a[0].localeCompare(b[0]));
  16.  
  17.  
  18. sortedItemd.forEach(element => {
  19.     console.log(`Term: ${element[0]} => Definition: ${element[1]}`);
  20. });
  21. }
Advertisement
RAW Paste Data Copied
Advertisement