Skip to content

Commit 1ff2e2f

Browse files
committed
add array generate
1 parent 20adf4d commit 1ff2e2f

File tree

6 files changed

+65
-68
lines changed

6 files changed

+65
-68
lines changed

src/App.css

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +0,0 @@
1-
.App {
2-
text-align: center;
3-
}
4-
5-
.App-logo {
6-
height: 40vmin;
7-
pointer-events: none;
8-
}
9-
10-
@media (prefers-reduced-motion: no-preference) {
11-
.App-logo {
12-
animation: App-logo-spin infinite 20s linear;
13-
}
14-
}
15-
16-
.App-header {
17-
background-color: #282c34;
18-
min-height: 100vh;
19-
display: flex;
20-
flex-direction: column;
21-
align-items: center;
22-
justify-content: center;
23-
font-size: calc(10px + 2vmin);
24-
color: white;
25-
}
26-
27-
.App-link {
28-
color: #61dafb;
29-
}
30-
31-
@keyframes App-logo-spin {
32-
from {
33-
transform: rotate(0deg);
34-
}
35-
to {
36-
transform: rotate(360deg);
37-
}
38-
}

src/App.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
import React from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
4-
1+
import React from "react";
2+
import "./App.css";
3+
import SortingVisualizer from "./components/SortingVisualizer.jsx";
54
function App() {
65
return (
76
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.js</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
7+
<SortingVisualizer />
228
</div>
239
);
2410
}

src/components/SortingVisualizer.css

Whitespace-only changes.

src/components/SortingVisualizer.jsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from "react";
2+
class SortingVisualizer extends React.Component {
3+
constructor(props) {
4+
super(props);
5+
6+
this.state = {
7+
array: [],
8+
};
9+
}
10+
11+
componentDidMount() {
12+
this.resetArray();
13+
}
14+
15+
/**
16+
* this method will reset global array
17+
*/
18+
19+
resetArray() {
20+
const array = [];
21+
for (let i = 0; i < 100; i++) {
22+
array.push(randomIntFromInterval(5, 1000));
23+
}
24+
this.setState({ array });
25+
}
26+
27+
render() {
28+
const { array } = this.state;
29+
return (
30+
<>
31+
{array.map((value, idx) => (
32+
<div className="array-bar" key={idx}>
33+
{value}
34+
</div>
35+
))}
36+
</>
37+
);
38+
}
39+
}
40+
41+
SortingVisualizer.propTypes = {};
42+
43+
export default SortingVisualizer;
44+
45+
/**
46+
*
47+
* @param {int} min
48+
* @param {int} max
49+
*/
50+
51+
function randomIntFromInterval(min, max) {
52+
return Math.floor(Math.random() * (max - min + 1) + min);
53+
}

src/index.css

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
body {
22
margin: 0;
3-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5-
sans-serif;
6-
-webkit-font-smoothing: antialiased;
7-
-moz-osx-font-smoothing: grayscale;
3+
padding: 0;
84
}
95

106
code {
11-
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
7+
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
128
monospace;
139
}

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import './index.css';
4-
import App from './App';
5-
import * as serviceWorker from './serviceWorker';
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import "./index.css";
4+
import App from "./App";
5+
import * as serviceWorker from "./serviceWorker";
66

77
ReactDOM.render(
88
<React.StrictMode>
99
<App />
1010
</React.StrictMode>,
11-
document.getElementById('root')
11+
document.getElementById("root")
1212
);
1313

1414
// If you want your app to work offline and load faster, you can change

0 commit comments

Comments
 (0)