Advertisement
isebs

Untitled

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