File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed
Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ export class PolyglotWordset extends Wordset {
161161 this . wordsMap = wordsMap ;
162162 this . resetIndexes ( ) ;
163163 this . length = Array . from ( this . wordsMap . values ( ) ) . reduce (
164- ( sum , ws ) => sum + ws . words . length ,
164+ ( sum , ws ) => sum + ws . length ,
165165 0 ,
166166 ) ;
167167 this . currLang = this . langs [ 0 ] as Language ;
@@ -172,7 +172,7 @@ export class PolyglotWordset extends Wordset {
172172 }
173173
174174 override resetIndexes ( ) : void {
175- this . wordsMap . forEach ( ( ws , _ ) => {
175+ this . wordsMap . forEach ( ( ws ) => {
176176 ws . resetIndexes ( ) ;
177177 } ) ;
178178 }
@@ -199,6 +199,12 @@ export class PolyglotWordset extends Wordset {
199199 override nextWord ( ) : string {
200200 return this . getWordset ( ) . nextWord ( ) ;
201201 }
202+
203+ override hasChar ( c : string ) : boolean {
204+ return Array . from ( this . wordsMap . values ( ) ) . some ( ( ws ) =>
205+ ws . words . includes ( c ) ,
206+ ) ;
207+ }
202208}
203209
204210const list : Partial < Record < FunboxName , FunboxFunctions > > = {
Original file line number Diff line number Diff line change @@ -707,12 +707,12 @@ export async function generateWords(
707707
708708 ret . hasTab =
709709 ret . words . some ( ( w ) => w . includes ( "\t" ) ) ||
710- currentWordset . words . some ( ( w ) => w . includes ( "\t" ) ) ||
710+ currentWordset . hasChar ( "\t" ) ||
711711 ( Config . mode === "quote" &&
712712 ( quote as QuoteWithTextSplit ) . textSplit . some ( ( w ) => w . includes ( "\t" ) ) ) ;
713713 ret . hasNewline =
714714 ret . words . some ( ( w ) => w . includes ( "\n" ) ) ||
715- currentWordset . words . some ( ( w ) => w . includes ( "\n" ) ) ||
715+ currentWordset . hasChar ( "\n" ) ||
716716 ( Config . mode === "quote" &&
717717 ( quote as QuoteWithTextSplit ) . textSplit . some ( ( w ) => w . includes ( "\n" ) ) ) ;
718718
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ export class Wordset {
2525
2626 randomWord ( mode : FunboxWordsFrequency ) : string {
2727 if ( mode === "zipf" ) {
28- return this . words [ zipfyRandomArrayIndex ( this . words . length ) ] as string ;
28+ return this . words [ zipfyRandomArrayIndex ( this . length ) ] as string ;
2929 } else {
3030 return randomElementFromArray ( this . words ) ;
3131 }
@@ -52,6 +52,10 @@ export class Wordset {
5252 }
5353 return this . words [ this . orderedIndex ++ ] as string ;
5454 }
55+
56+ hasChar ( c : string ) : boolean {
57+ return this . words . some ( ( w ) => w . includes ( c ) ) ;
58+ }
5559}
5660
5761export async function withWords ( words : string [ ] ) : Promise < Wordset > {
You can’t perform that action at this time.
0 commit comments