Updates trie function

This commit is contained in:
Mouse Reeve 2022-01-10 16:44:43 -08:00
parent 2746318152
commit f6d6285009

View file

@ -52,24 +52,22 @@
return []; return [];
} }
return searchTrie(input, trie); return searchTrie(trie);
} }
function searchTrie(output, trie) { function searchTrie(trie) {
const options = Object.keys(trie); const options = Object.values(trie);
if (!options.length) { if (!options.length) {
return [output]; return;
} else if (typeof options[0] == 'string') {
return [options[0]];
} }
return options.map(option => { return options.map(option => {
const newTrie = trie[option]; const newTrie = option;
if (!newTrie) { return searchTrie(newTrie);
return;
}
return searchTrie(output + option, trie[option]);
}).reduce((prev, next) => prev.concat(next)); }).reduce((prev, next) => prev.concat(next));
} }
@ -83,14 +81,11 @@
const mimetypeTrie = { const mimetypeTrie = {
"p": { "p": {
"d": { "d": {
"f": { "f": "PDF",
"": {},
"x": {},
},
}, },
"n": { "n": {
"g": {} "g": "PNG",
}, },
} },
}; };