Advertisement
drak138

Обяснение на 6-та

Mar 1st, 2024
768
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.     // Превръщаме стринга в обект с parse
  6.       let obj = JSON.parse(jsonStr);
  7.     // С Object.entries() превръщаме обекта в array и задаваме вече какво е term и definition
  8.       let [term, definition] = Object.entries(obj)[0];
  9.    // Казваме в обекта dictionary Coffee: definition и по условие автоматично го променяме ако coffee е споменато отново еквивалентното на
  10.         // let a=5
  11.         //     a=8
  12.       dictionary[term] = definition;
  13.     }
  14.  
  15.   //Сортираме по ключа(term) по азбучен ред ако оставим sort празен той соритра по ASCII таблицата
  16.     let sortedTerms = Object.keys(dictionary).sort();
  17.  
  18.   //Минаваме през всеки термин
  19.     for (let term of sortedTerms) {
  20.         //създаваме дефиниция която е равна на dictionary[term] еквивалентното на let a= arr[0]
  21.       let definition = dictionary[term];
  22.       console.log(`Term: ${term} => Definition: ${definition}`);
  23.     }
  24.   }
  25.   makeDictionary([
  26.     '{"Coffee":"A hot drink made from the roasted and ground seeds (coffee beans) of a tropical shrub."}',
  27.     '{"Bus":"A large motor vehicle carrying passengers by road, typically one serving the public on a fixed route and for a fare."}',
  28.     '{"Boiler":"A fuel-burning apparatus or container for heating water."}',
  29.     '{"Tape":"A narrow strip of material, typically used to holdor fasten something."}',
  30.     '{"Microphone":"An instrument for converting sound waves into electrical energy variations which may then be amplified, transmitted, or recorded."}',
  31.   ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement