Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function makeDictionary(arr) {
- let dictionary = {};
- for (let jsonStr of arr) {
- // Превръщаме стринга в обект с parse
- let obj = JSON.parse(jsonStr);
- // С Object.entries() превръщаме обекта в array и задаваме вече какво е term и definition
- let [term, definition] = Object.entries(obj)[0];
- // Казваме в обекта dictionary Coffee: definition и по условие автоматично го променяме ако coffee е споменато отново еквивалентното на
- // let a=5
- // a=8
- dictionary[term] = definition;
- }
- //Сортираме по ключа(term) по азбучен ред ако оставим sort празен той соритра по ASCII таблицата
- let sortedTerms = Object.keys(dictionary).sort();
- //Минаваме през всеки термин
- for (let term of sortedTerms) {
- //създаваме дефиниция която е равна на dictionary[term] еквивалентното на let a= arr[0]
- let definition = dictionary[term];
- console.log(`Term: ${term} => Definition: ${definition}`);
- }
- }
- makeDictionary([
- '{"Coffee":"A hot drink made from the roasted and ground seeds (coffee beans) of a tropical shrub."}',
- '{"Bus":"A large motor vehicle carrying passengers by road, typically one serving the public on a fixed route and for a fare."}',
- '{"Boiler":"A fuel-burning apparatus or container for heating water."}',
- '{"Tape":"A narrow strip of material, typically used to holdor fasten something."}',
- '{"Microphone":"An instrument for converting sound waves into electrical energy variations which may then be amplified, transmitted, or recorded."}',
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement