Advertisement
Pijomir

Untitled

Sep 14th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. function makeADictionary(input) {
  2. let dictionary = [];
  3. input.forEach(element => {
  4. let parsedEl = JSON.parse(element);
  5. let termAndDefinition = Object.entries(parsedEl);
  6. let [Term, Definition] = termAndDefinition[0];
  7. let foundTerm = dictionary.find(a => a.Term === Term);
  8. if (foundTerm) {
  9. dictionary.Term = Definition;
  10. }else {
  11. dictionary.push({Term, Definition});
  12. }
  13. });
  14.  
  15. let sortedDictionary = dictionary.sort((a, b) => a.Term.localeCompare(b.Term));
  16.  
  17. sortedDictionary.forEach(a => {
  18. console.log(`Term: ${a.Term} => Definition: ${a.Definition}`);
  19. });
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement