Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- class Term {
- constructor(word, definition) {
- this.word = word;
- this.definition = definition;
- }
- }
- const words = [];
- const definitions = [];
- for (const line of arr) {
- const currentTerm = JSON.parse(line);
- const currentWord = Object.keys(currentTerm)[0];
- const currentDefinition = Object.values(currentTerm)[0];
- const termIndex = words.indexOf(currentWord);
- if (termIndex > -1) {
- definitions[termIndex] = currentDefinition;
- } else {
- words.push(currentWord);
- definitions.push(currentDefinition);
- }
- }
- const terms = [];
- for (let i = 0; i < words.length; i++) {
- terms.push(new Term(words[i], definitions[i]));
- }
- terms.sort((a, b) => a.word.localeCompare(b.word)).forEach(term => {
- console.log(`Term: ${term.word} => Definition: ${term.definition}`);
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement