Advertisement
nikolayneykov

Untitled

Apr 6th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve ([wordsWithDefinitions, wordsToCheck, command]) {
  2.   let dictionary = {}
  3.  
  4.   wordsWithDefinitions
  5.     .split(' | ')
  6.     .map(x => x.split(': '))
  7.     .forEach(([word, definition]) => {
  8.       if (!dictionary.hasOwnProperty(word)) {
  9.         dictionary[word] = []
  10.       }
  11.  
  12.       dictionary[word].push(definition)
  13.     })
  14.  
  15.   wordsToCheck.split(' | ').forEach(word => {
  16.     if (dictionary.hasOwnProperty(word)) {
  17.       console.log(word)
  18.       dictionary[word]
  19.         .sort((a, b) => b.length - a.length)
  20.         .forEach(definition => {
  21.           console.log(` -${definition}`)
  22.         })
  23.     }
  24.   })
  25.  
  26.   if (command === 'List') {
  27.     console.log(
  28.       Object.keys(dictionary)
  29.         .sort((a, b) => a.localeCompare(b))
  30.         .join(' ')
  31.     )
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement