victoriaSD

Untitled

Mar 1st, 2024
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function makeDictionary(arr) {
  2.   let dictionary = {};
  3.  
  4.   for (let jsonStr of arr) {
  5.     let obj = JSON.parse(jsonStr);
  6.    
  7.     let [term, definition] = Object.entries(obj)[0];
  8.  
  9.     dictionary[term] = definition.trim();
  10.   }
  11.  
  12.  
  13.   let sortedTerms = Object.keys(dictionary).sort();
  14.  
  15.  
  16.   for (let term of sortedTerms) {
  17.     let definition = dictionary[term];
  18.     console.log(`Term: ${term} => Definition: ${definition}`);
  19.   }
  20. }
  21.  
  22. makeDictionary([
  23.   '{"Coffee":"A hot drink made from the roasted and ground seeds (coffee beans) of a tropical shrub."}',
  24.   '{"Bus":"A large motor vehicle carrying passengers by road, typically one serving the public on a fixed route and for a fare."}',
  25.   '{"Boiler":"A fuel-burning apparatus or container for heating water."}',
  26.   '{"Tape":"A narrow strip of material, typically used to holdor fasten something."}',
  27.   '{"Microphone":"An instrument for converting sound waves into electrical energy variations which may then be amplified, transmitted, or recorded."}',
  28. ]);
Advertisement
Add Comment
Please, Sign In to add comment