Advertisement
VeselaVideva

Objects and Classes - Exercise - 06. Make a Dictionary

Oct 23rd, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dictionary(input) {
  2.     let dictionary = {};
  3.  
  4.     for (let element of input) {
  5.         let obj = JSON.parse(element);
  6.         dictionary = Object.assign(dictionary, obj);
  7.     }
  8.  
  9.     let sortedKeys = Object.keys(dictionary);
  10.     sortedKeys.sort((a, b) => a.localeCompare(b));
  11.  
  12.     for (let term of sortedKeys) {
  13.         let def = dictionary[term];
  14.         console.log(`Term: ${term} => Definition: ${def}`);
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement