File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const randomItem = ( not ) => {
2- let item ;
3-
4- do {
5- const idx = Math . floor ( Math . random ( ) * window . ITEMS . length ) ;
6- item = window . ITEMS [ idx ] ;
7- } while ( not && item === not ) ;
8-
9- return item ;
10- } ;
11-
121const infoText = document . querySelector ( "#info-text" ) ;
132
143function next ( ) {
154 infoText . textContent = "" ;
16- const item = randomItem ( ) ;
5+
6+ const candiates = [ ...window . ITEMS ] ;
7+
8+ const nextRandomItem = ( ) => {
9+ const idx = Math . floor ( Math . random ( ) * candiates . length ) ;
10+ const result = candiates [ idx ] ;
11+ candiates . splice ( idx , 1 ) ;
12+ return result ;
13+ } ;
14+
15+ const item = nextRandomItem ( ) ;
1716
1817 const mangle = Math . random ( ) > 0.5 ;
1918
@@ -24,10 +23,10 @@ function next() {
2423 children [ 1 ] . textContent = mangle ? item . means : item . mangle ;
2524
2625 const options = [
27- randomItem ( item ) ,
28- randomItem ( item ) ,
29- randomItem ( item ) ,
30- randomItem ( item ) ,
26+ nextRandomItem ( item ) ,
27+ nextRandomItem ( item ) ,
28+ nextRandomItem ( item ) ,
29+ nextRandomItem ( item ) ,
3130 ] ;
3231 const correctIdx = Math . floor ( Math . random ( ) * options . length ) ;
3332 options [ correctIdx ] = item ;
You can’t perform that action at this time.
0 commit comments