Advertisement
vladovip

JS_FUND FINEX DictionaryV1

May 1st, 2022
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dictionary(inputArr) {
  2.   let wordDefinitionLine = inputArr.shift().split(" | ");
  3.   // console.log(wordDefinitionLine);
  4.   let wordLineArr = inputArr.shift().split(" | ");
  5.   // console.log(wordLineArr);
  6.   let command = inputArr.shift();
  7.   // console.log(command);
  8.   let libraryRecords = {};
  9.  
  10.   for (let element of wordDefinitionLine) {
  11.     let tokens = element.split(": ");
  12.     let word = tokens[0];
  13.     let explanation = tokens[1];
  14.     if (libraryRecords.hasOwnProperty(word) == false) {
  15.       libraryRecords[word] = [];
  16.       libraryRecords[word].push(`${explanation}`);
  17.     } else if (libraryRecords.hasOwnProperty(word) == true) {
  18.       if (libraryRecords[word].includes(explanation) == false) {
  19.         libraryRecords[word].push(`${explanation}`);
  20.       }
  21.     }
  22.   }
  23.  
  24.   // for( let word in libraryRecords){
  25.   //     console.log(`${word} : ${libraryRecords[word]}`);
  26.   // }
  27.  
  28.   if (command == "Test") {
  29.     for (let testedWord of wordLineArr) {
  30.       if (libraryRecords.hasOwnProperty(testedWord) == true) {
  31.         console.log(`${testedWord}:`);
  32.         // console.log(libraryRecords[testedWord]);
  33.         for( let element of libraryRecords[testedWord] ){
  34.             console.log(`-${element}`);
  35.         }
  36.       }
  37.     }
  38.   }
  39.  
  40.   if ( command == "Hand Over"){
  41.       let arrOfWords = Object.keys(libraryRecords);
  42.       console.log(arrOfWords.join(" "));
  43.   }
  44.  
  45.  
  46. }
  47.  
  48. dictionary([
  49.   "programmer: an animal, which turns coffee into code | developer: a magician",
  50.   "fish | domino",
  51.   "Hand Over",
  52. ]);
  53.  
  54. console.log(`-------`);
  55.  
  56. dictionary([
  57.   "care: worry, anxiety, or concern | care: a state of mind in which one is troubled | face: the front part of the head, from the forehead to the chin",
  58.   "care | kitchen | flower",
  59.   "Test",
  60. ]);
  61.  
  62. console.log(`---------`);
  63.  
  64. dictionary([
  65.   "tackle: the equipment required for a task or sport | code: write code for a computer program | bit: a small piece, part, or quantity of something | tackle: make determined efforts to deal with a problem | bit: a short time or distance",
  66.   "bit | code | tackle",
  67.   "Test",
  68. ]);
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement