Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let dictionary = [];
- class Term {
- constructor(name, description) {
- this.name = name;
- this.description = description;
- }
- }
- for (let element of arr) {
- const term = JSON.parse(element);
- const name = Object.keys(term)[0];
- if (dictionary.filter(ele => ele.name === name).length > 0) {
- let termtoChange = dictionary.filter(ele => ele.name === name)[0];
- termtoChange.description = term[Object.keys(term)[0]];
- } else {
- dictionary.push(parseIntoInstanse(term));
- }
- }
- for (const term of dictionary.sort(((a, b) => a.name.localeCompare(b.name)))) {
- console.log(`Term: ${term.name} => Definition: ${term.description}`);
- }
- function parseIntoInstanse(obj) {
- let term = new Term(Object.keys(obj)[0], obj[Object.keys(obj)[0]]);
- return term;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement