1
1
const adjectives = [ "pretty" , "large" , "big" , "small" , "tall" , "short" , "long" , "handsome" , "plain" , "quaint" , "clean" , "elegant" , "easy" , "angry" , "crazy" , "helpful" , "mushy" , "odd" , "unsightly" , "adorable" , "important" , "inexpensive" , "cheap" , "expensive" , "fancy" ] ;
2
2
const colours = [ "red" , "yellow" , "blue" , "green" , "pink" , "brown" , "purple" , "brown" , "white" , "black" , "orange" ] ;
3
3
const nouns = [ "table" , "chair" , "house" , "bbq" , "desk" , "car" , "pony" , "cookie" , "sandwich" , "burger" , "pizza" , "mouse" , "keyboard" ] ;
4
- const lengths = [ adjectives . length , colours . length , nouns . length ] ;
5
- function * _random ( n ) {
6
- for ( let max of lengths ) {
7
- const arr = new Array ( n ) ;
8
- for ( i = 0 ; i < n ; i ++ ) arr [ i ] = Math . round ( Math . random ( ) * 1000 ) % max ;
9
- yield arr
10
- }
11
- }
4
+ const [ l1 , l2 , l3 ] = [ adjectives . length , colours . length , nouns . length ] ;
12
5
const data = [ ] , nTemplates = ( n ) => Math . round ( n / 100 ) , tbody = document . getElementsByTagName ( 'tbody' ) [ 0 ] ;
13
6
let index = 1 , i , lbl , selected ;
14
7
@@ -35,7 +28,7 @@ function set(n) {
35
28
}
36
29
}
37
30
function append ( n = 1000 ) {
38
- const [ r1 , r2 , r3 ] = _random ( n ) , nt = nTemplates ( n ) ; let j = 0 ;
31
+ const nt = nTemplates ( n ) ; let j = 0 , r1 , r2 , r3 ;
39
32
const itemTemplate = document . getElementById ( 'itemTemplate' ) . content ;
40
33
while ( nt >= itemTemplate . children . length * 2 ) itemTemplate . appendChild ( itemTemplate . cloneNode ( true ) ) ;
41
34
while ( nt > itemTemplate . children . length ) itemTemplate . appendChild ( itemTemplate . firstElementChild . cloneNode ( true ) ) ;
@@ -45,6 +38,9 @@ function append(n = 1000) {
45
38
46
39
while ( ( n -= nt ) >= 0 ) {
47
40
for ( i = 0 ; i < nt ; i ++ , j ++ ) {
41
+ r1 = Math . round ( Math . random ( ) * 1000 ) % l1 ;
42
+ r2 = Math . round ( Math . random ( ) * 1000 ) % l2 ;
43
+ r3 = Math . round ( Math . random ( ) * 1000 ) % l3 ;
48
44
ids [ i ] . nodeValue = index ++ ;
49
45
data . push ( labels [ i ] . nodeValue = `${ adjectives [ r1 [ j ] ] } ${ colours [ r2 [ j ] ] } ${ nouns [ r3 [ j ] ] } ` )
50
46
}
@@ -53,7 +49,7 @@ function append(n = 1000) {
53
49
}
54
50
function update ( ) {
55
51
const labels = tbody . querySelectorAll ( 'a.lbl' ) , length = labels . length ;
56
- for ( i = 0 ; i < length ; i += 10 ) labels [ i ] . firstChild . nodeValue = data [ i ] += ' !!!' ;
52
+ for ( i = 0 ; i < length ; i += 10 ) labels [ i ] . firstChild . nodeValue = data [ i ] = ` ${ data [ i ] } !!!` ;
57
53
}
58
54
function clear ( ) { data . length = 0 ; tbody . textContent = '' }
59
55
0 commit comments