File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,14 @@ import { create } from "zustand"
22
33interface QsStore {
44 question : [ string , string ] [ ]
5+ lastIndex : number
56 setQuestion : ( qsString : string ) => void
67 getRandomQuestion : ( ) => [ string , string ]
78}
89
910const useQsStore = create < QsStore > ( ( set , get ) => ( {
1011 question : [ ] ,
12+ lastIndex : - 1 ,
1113
1214 setQuestion : ( qsString : string ) => {
1315 if ( ! qsString ?. trim ( ) ) {
@@ -47,7 +49,10 @@ const useQsStore = create<QsStore>((set, get) => ({
4749 getRandomQuestion : ( ) => {
4850 const questions = get ( ) . question
4951 const count = questions . length
50- const randomIndex = Math . floor ( Math . random ( ) * count )
52+ let randomIndex = Math . floor ( Math . random ( ) * count )
53+ while ( randomIndex === get ( ) . lastIndex ) {
54+ randomIndex = Math . floor ( Math . random ( ) * count )
55+ }
5156 console . log ( questions [ randomIndex ] )
5257 return questions [ randomIndex ]
5358 }
You can’t perform that action at this time.
0 commit comments