Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let dictionary = {};
- let definitions = arr.shift();
- definitions = definitions.split(' | ').forEach(line => {
- let [word, definition] = line.split(': ');
- if (!dictionary.hasOwnProperty(word)) {
- dictionary[word] = [definition];
- } else {
- dictionary[word].push(definition);
- }
- })
- let onTest = arr.shift();
- let commandParser = {
- 'Test': () => {
- onTest = onTest.split(' | ').forEach(w => {
- if (dictionary.hasOwnProperty(w)) {
- console.log(`${w}`);
- Object.entries(dictionary[w]).sort((a, b) => b[1].length - a[1].length).forEach(x => console.log(`-${x[1]}`));
- }
- })
- },
- 'Hand Over': () => {
- console.log(Object.keys(dictionary).join(' '));
- }
- }
- commandParser[arr.join()]();
- }
Add Comment
Please, Sign In to add comment