Advertisement
Pijomir

Make A Dictionary

Oct 28th, 2023 (edited)
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function makeDictionary(input) {
  2.     let dictionary = {};
  3.     for (let line of input) {
  4.         let currentWordAndDefinition = JSON.parse(line);
  5.         let [currentWord, currentDefinition] = Object.entries(currentWordAndDefinition[0]);
  6.         dictionary[currentWord] = currentDefinition;
  7.     }
  8.  
  9.     let sortedDictionary = Object.entries(dictionary).sort((a, b) => a[0].localeCompare(b[0]));
  10.     sortedDictionary.forEach(a => console.log(`Term: ${a[0]} => Definition: ${a[1]}`));
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement