Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve ([wordsWithDefinitions, wordsToCheck, command]) {
- let dictionary = {}
- wordsWithDefinitions
- .split(' | ')
- .map(x => x.split(': '))
- .forEach(([word, definition]) => {
- if (!dictionary.hasOwnProperty(word)) {
- dictionary[word] = []
- }
- dictionary[word].push(definition)
- })
- wordsToCheck.split(' | ').forEach(word => {
- if (dictionary.hasOwnProperty(word)) {
- console.log(word)
- dictionary[word]
- .sort((a, b) => b.length - a.length)
- .forEach(definition => {
- console.log(` -${definition}`)
- })
- }
- })
- if (command === 'List') {
- console.log(
- Object.keys(dictionary)
- .sort((a, b) => a.localeCompare(b))
- .join(' ')
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement