@@ -7,10 +7,10 @@ import MergeSort from './src/algorithms/MergeSort';
7
7
import ShellSort from './src/algorithms/ShellSort' ;
8
8
9
9
// 0: slowest, 500: fastest
10
- const DEFAULT_SORT_SPEED = 24.7 ;
11
- const MAX_SPEED = 50 ;
12
- const MIN_SPEED = 1 ;
13
- const NUMBERS_AMOUNT = 100 ;
10
+ const DEFAULT_SORT_SPEED = 5 ;
11
+ const MAX_SPEED = 500 ;
12
+ const MIN_SPEED = 0 ;
13
+ const NUMBERS_AMOUNT = 50 ;
14
14
15
15
export default class App extends React . Component {
16
16
sortAlgorithm ;
@@ -27,14 +27,14 @@ export default class App extends React.Component {
27
27
}
28
28
29
29
resetTimer ( ) {
30
- if ( this . intervalId )
30
+ if ( this . intervalId ) {
31
31
clearInterval ( this . intervalId ) ;
32
+ }
32
33
this . intervalId = setInterval ( ( ) => {
33
- if ( ! this . sortAlgorithm )
34
+ if ( ! this . sortAlgorithm ) {
34
35
return ;
35
- while ( ! this . sortAlgorithm . isCompleted ( ) && ! this . sortAlgorithm . next ( ) ) {
36
-
37
36
}
37
+ while ( ! this . sortAlgorithm . isCompleted ( ) && ! this . sortAlgorithm . next ( ) ) { }
38
38
this . setState ( ( ) => {
39
39
return {
40
40
data : this . sortAlgorithm . getData ( ) ,
@@ -44,14 +44,17 @@ export default class App extends React.Component {
44
44
}
45
45
46
46
generateRandomValues ( amount ) {
47
- values = [ ] ;
48
- for ( var i = 0 ; i < amount ; i ++ )
49
- values [ i ] = parseInt ( Math . random ( ) * 100 ) ;
47
+ let values = [ ] ;
48
+ for ( var i = 0 ; i < amount ; i ++ ) {
49
+ values [ i ] = parseInt ( Math . random ( ) * NUMBERS_AMOUNT + 1 ) ;
50
+ }
50
51
return values ;
51
52
}
52
53
53
54
setBubbleSort ( ) {
54
- this . sortAlgorithm = new BubbleSort ( this . generateRandomValues ( NUMBERS_AMOUNT ) ) ;
55
+ this . sortAlgorithm = new BubbleSort (
56
+ this . generateRandomValues ( NUMBERS_AMOUNT ) ,
57
+ ) ;
55
58
this . setState ( ( ) => {
56
59
return {
57
60
data : this . sortAlgorithm . getData ( ) ,
@@ -60,7 +63,9 @@ export default class App extends React.Component {
60
63
}
61
64
62
65
setQuickSort ( ) {
63
- this . sortAlgorithm = new QuickSort ( this . generateRandomValues ( NUMBERS_AMOUNT ) ) ;
66
+ this . sortAlgorithm = new QuickSort (
67
+ this . generateRandomValues ( NUMBERS_AMOUNT ) ,
68
+ ) ;
64
69
this . setState ( ( ) => {
65
70
return {
66
71
data : this . sortAlgorithm . getData ( ) ,
@@ -69,7 +74,9 @@ export default class App extends React.Component {
69
74
}
70
75
71
76
setMergeSort ( ) {
72
- this . sortAlgorithm = new MergeSort ( this . generateRandomValues ( NUMBERS_AMOUNT ) ) ;
77
+ this . sortAlgorithm = new MergeSort (
78
+ this . generateRandomValues ( NUMBERS_AMOUNT ) ,
79
+ ) ;
73
80
this . setState ( ( ) => {
74
81
return {
75
82
data : this . sortAlgorithm . getData ( ) ,
@@ -78,7 +85,9 @@ export default class App extends React.Component {
78
85
}
79
86
80
87
setShellSort ( ) {
81
- this . sortAlgorithm = new ShellSort ( this . generateRandomValues ( NUMBERS_AMOUNT ) ) ;
88
+ this . sortAlgorithm = new ShellSort (
89
+ this . generateRandomValues ( NUMBERS_AMOUNT ) ,
90
+ ) ;
82
91
this . setState ( ( ) => {
83
92
return {
84
93
data : this . sortAlgorithm . getData ( ) ,
0 commit comments