Advertisement
Pijomir

Make A Dictionary

Sep 14th, 2022
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function makeADictionary(input) {
  2.     let dictionary = {};
  3.     for (let el of input) {
  4.         let parsedInput = JSON.parse(el);
  5.         let entries = Object.entries(parsedInput);
  6.         let [term, definition] = entries[0];
  7.         dictionary[term] = definition;
  8.     }
  9.  
  10.     let sortedDictionary = Object.entries(dictionary).sort((a, b) => a[0].localeCompare(b[0]));
  11.     sortedDictionary.forEach(a => console.log(`Term: ${a[0]} => Definition: ${a[1]}`));
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement