Advertisement
Guest User

Untitled

a guest
Apr 13th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dictionary(inputArea) {
  2.     let inputs = inputArea;
  3.     let areaOfWordsAndDescriptions = inputs[0].split(" | ").map((x) => x.split(": "));
  4.     let wordsToPrint = inputs[1].split(" | ");
  5.  
  6.     wordsToPrint.forEach(word => {
  7.         let areaOfDescr = [];
  8.         areaOfWordsAndDescriptions.forEach(description => {
  9.             if (word === description[0]) {
  10.                 areaOfDescr.push(description[1]);
  11.             }
  12.         });
  13.         if (areaOfDescr.length >= 1) {
  14.             console.log(word);
  15.             console.log('-' + (areaOfDescr.sort((a, b) => b.length - a.length)).join("\n-"));
  16.         }
  17.     });
  18.  
  19.     if (inputs[2] === "List") {
  20.         let tempArea = [];
  21.         areaOfWordsAndDescriptions.forEach(word => {
  22.             if (!tempArea.includes(word[0])) {
  23.                 tempArea.push(word[0])
  24.             }
  25.         });
  26.         console.log(tempArea.sort((a, b) => a > b).join(" "));
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement