add dict from imported json
This commit is contained in:
parent
c5e439e567
commit
be91004c3a
1 changed files with 8 additions and 4 deletions
|
@ -9,10 +9,9 @@ export class Dict {
|
||||||
this.letters = new Set([...words.values()].map((w) => w.split("")).flat());
|
this.letters = new Set([...words.values()].map((w) => w.split("")).flat());
|
||||||
}
|
}
|
||||||
|
|
||||||
static async from_file(path: string, length: number) {
|
static from_lines(lines: string[], length: number) {
|
||||||
const words = new Set<string>();
|
const words = new Set<string>();
|
||||||
const content = await Deno.readTextFile(path);
|
for (const word of lines) {
|
||||||
for (const word of content.split("\n")) {
|
|
||||||
const word_ = word.trim().toLowerCase();
|
const word_ = word.trim().toLowerCase();
|
||||||
if (word_.length !== length) continue;
|
if (word_.length !== length) continue;
|
||||||
if (contains_any(word_, [" ", "-", "."])) continue;
|
if (contains_any(word_, [" ", "-", "."])) continue;
|
||||||
|
@ -21,8 +20,13 @@ export class Dict {
|
||||||
return new Dict(words, length);
|
return new Dict(words, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async from_text_file(path: string, length: number) {
|
||||||
|
const content = await Deno.readTextFile(path);
|
||||||
|
return Dict.from_lines(content.split("\n"), length);
|
||||||
|
}
|
||||||
|
|
||||||
[Symbol.for("Deno.customInspect")]() {
|
[Symbol.for("Deno.customInspect")]() {
|
||||||
return `Dict { ${this.words.size} words }`;
|
return `Dict { ${this.words.size} words, ${this.letters.size} letters }`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue