File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -20,4 +20,27 @@ class Utils {
20
20
return arg1 [ Utils . random ( 0 , arg1 . length ) ] ;
21
21
}
22
22
}
23
+
24
+ /**
25
+ * Creates an array of unique items
26
+ * @param data The array of data to get elements from
27
+ * @param amount The number of elements in the unique array
28
+ * @param limit The max number of operations before the unique array is returned (default 1000)
29
+ */
30
+ public static createUniqueList ( data : any [ ] , amount : number , limit ?: number ) : any [ ] {
31
+ const result : any [ ] = [ ] ;
32
+
33
+ let counter : number = 0 ;
34
+ while ( result . length < amount && counter < ( limit || 100 ) ) {
35
+ const item : any = data [ Utils . random ( 0 , data . length ) ] ;
36
+
37
+ if ( ! result . includes ( item ) ) {
38
+ result . push ( item ) ;
39
+ }
40
+
41
+ counter ++ ;
42
+ }
43
+
44
+ return result ;
45
+ }
23
46
}
Original file line number Diff line number Diff line change 4
4
"baseUrl" : " ./src/ts/" ,
5
5
"outFile" : " ./src/output/build.js" ,
6
6
"lib" : [
7
- " es2015 " ,
7
+ " es2016 " ,
8
8
" dom"
9
9
],
10
10
"module" : " system" ,
You can’t perform that action at this time.
0 commit comments