20 | );
21 | }
22 | }
23 |
24 | export default App;
25 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Big-O Performance
7 |
8 |
9 |
10 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 rramatchandran
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Calcs.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import './Calcs.css';
3 |
4 | function factorial(x) {
5 | if(!x) {
6 | return 1;
7 | }
8 | if (x === 0){
9 | return 1;
10 | }
11 | return x * factorial(x-1);
12 | }
13 |
14 | class Calcs extends Component {
15 | constructor(props){
16 | super(props);
17 | this.state = {value: 0};
18 | }
19 | handleChange(event) {
20 | this.setState({value: event.target.value});
21 | }
22 |
23 | render() {
24 | return (
25 |
184 | );
185 | }
186 | }
187 |
188 | export default Charts;
189 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # big-o-performance
2 | A simple html app to demonstrate performance costs of data structures.
3 |
4 | - Clone the project
5 | - Navigate to the root of the project in a termina or command prompt
6 | - Run 'npm install'
7 | - Run 'npm start'
8 | - Go to the URL specified in the terminal or command prompt to try out the app.
9 |
10 | # This app was created from the Create React App NPM. Below are instructions from that project.
11 |
12 | Below you will find some information on how to perform common tasks.
13 | You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/template/README.md).
14 |
15 | ## Table of Contents
16 |
17 | - [Updating to New Releases](#updating-to-new-releases)
18 | - [Sending Feedback](#sending-feedback)
19 | - [Folder Structure](#folder-structure)
20 | - [Available Scripts](#available-scripts)
21 | - [npm start](#npm-start)
22 | - [npm run build](#npm-run-build)
23 | - [npm run eject](#npm-run-eject)
24 | - [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor)
25 | - [Installing a Dependency](#installing-a-dependency)
26 | - [Importing a Component](#importing-a-component)
27 | - [Adding a Stylesheet](#adding-a-stylesheet)
28 | - [Post-Processing CSS](#post-processing-css)
29 | - [Adding Images and Fonts](#adding-images-and-fonts)
30 | - [Adding Bootstrap](#adding-bootstrap)
31 | - [Adding Flow](#adding-flow)
32 | - [Adding Custom Environment Variables](#adding-custom-environment-variables)
33 | - [Integrating with a Node Backend](#integrating-with-a-node-backend)
34 | - [Proxying API Requests in Development](#proxying-api-requests-in-development)
35 | - [Deployment](#deployment)
36 | - [Now](#now)
37 | - [Heroku](#heroku)
38 | - [Surge](#surge)
39 | - [GitHub Pages](#github-pages)
40 | - [Something Missing?](#something-missing)
41 |
42 | ## Updating to New Releases
43 |
44 | Create React App is divided into two packages:
45 |
46 | * `create-react-app` is a global command-line utility that you use to create new projects.
47 | * `react-scripts` is a development dependency in the generated projects (including this one).
48 |
49 | You almost never need to update `create-react-app` itself: it’s delegates all the setup to `react-scripts`.
50 |
51 | When you run `create-react-app`, it always creates the project with the latest version of `react-scripts` so you’ll get all the new features and improvements in newly created apps automatically.
52 |
53 | To update an existing project to a new version of `react-scripts`, [open the changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md), find the version you’re currently on (check `package.json` in this folder if you’re not sure), and apply the migration instructions for the newer versions.
54 |
55 | In most cases bumping the `react-scripts` version in `package.json` and running `npm install` in this folder should be enough, but it’s good to consult the [changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md) for potential breaking changes.
56 |
57 | We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly.
58 |
59 | ## Sending Feedback
60 |
61 | We are always open to [your feedback](https://github.com/facebookincubator/create-react-app/issues).
62 |
63 | ## Folder Structure
64 |
65 | After creation, your project should look like this:
66 |
67 | ```
68 | my-app/
69 | README.md
70 | index.html
71 | favicon.ico
72 | node_modules/
73 | package.json
74 | src/
75 | App.css
76 | App.js
77 | index.css
78 | index.js
79 | logo.svg
80 | ```
81 |
82 | For the project to build, **these files must exist with exact filenames**:
83 |
84 | * `index.html` is the page template;
85 | * `favicon.ico` is the icon you see in the browser tab;
86 | * `src/index.js` is the JavaScript entry point.
87 |
88 | You can delete or rename the other files.
89 |
90 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.
91 | You need to **put any JS and CSS files inside `src`**, or Webpack won’t see them.
92 |
93 | You can, however, create more top-level directories.
94 | They will not be included in the production build so you can use them for things like documentation.
95 |
96 | ## Available Scripts
97 |
98 | In the project directory, you can run:
99 |
100 | ### `npm start`
101 |
102 | Runs the app in the development mode.
103 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
104 |
105 | The page will reload if you make edits.
106 | You will also see any lint errors in the console.
107 |
108 | ### `npm run build`
109 |
110 | Builds the app for production to the `build` folder.
111 | It correctly bundles React in production mode and optimizes the build for the best performance.
112 |
113 | The build is minified and the filenames include the hashes.
114 | Your app is ready to be deployed!
115 |
116 | ### `npm run eject`
117 |
118 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
119 |
120 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
121 |
122 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
123 |
124 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
125 |
126 | ## Displaying Lint Output in the Editor
127 |
128 | >Note: this feature is available with `react-scripts@0.2.0` and higher.
129 |
130 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint.
131 |
132 | They are not required for linting. You should see the linter output right in your terminal as well as the browser console. However, if you prefer the lint results to appear right in your editor, there are some extra steps you can do.
133 |
134 | You would need to install an ESLint plugin for your editor first.
135 |
136 | >**A note for Atom `linter-eslint` users**
137 |
138 | >If you are using the Atom `linter-eslint` plugin, make sure that **Use global ESLint installation** option is checked:
139 |
140 | >
141 |
142 | Then make sure `package.json` of your project ends with this block:
143 |
144 | ```js
145 | {
146 | // ...
147 | "eslintConfig": {
148 | "extends": "./node_modules/react-scripts/config/eslint.js"
149 | }
150 | }
151 | ```
152 |
153 | Projects generated with `react-scripts@0.2.0` and higher should already have it.
154 | If you don’t need ESLint integration with your editor, you can safely delete those three lines from your `package.json`.
155 |
156 | Finally, you will need to install some packages *globally*:
157 |
158 | ```sh
159 | npm install -g eslint babel-eslint eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-flowtype
160 | ```
161 |
162 | We recognize that this is suboptimal, but it is currently required due to the way we hide the ESLint dependency. The ESLint team is already [working on a solution to this](https://github.com/eslint/eslint/issues/3458) so this may become unnecessary in a couple of months.
163 |
164 | ## Installing a Dependency
165 |
166 | The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`:
167 |
168 | ```
169 | npm install --save
170 | ```
171 |
172 | ## Importing a Component
173 |
174 | This project setup supports ES6 modules thanks to Babel.
175 | While you can still use `require()` and `module.exports`, we encourage you to use [`import` and `export`](http://exploringjs.com/es6/ch_modules.html) instead.
176 |
177 | For example:
178 |
179 | ### `Button.js`
180 |
181 | ```js
182 | import React, { Component } from 'react';
183 |
184 | class Button extends Component {
185 | render() {
186 | // ...
187 | }
188 | }
189 |
190 | export default Button; // Don’t forget to use export default!
191 | ```
192 |
193 | ### `DangerButton.js`
194 |
195 |
196 | ```js
197 | import React, { Component } from 'react';
198 | import Button from './Button'; // Import a component from another file
199 |
200 | class DangerButton extends Component {
201 | render() {
202 | return ;
203 | }
204 | }
205 |
206 | export default DangerButton;
207 | ```
208 |
209 | Be aware of the [difference between default and named exports](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281). It is a common source of mistakes.
210 |
211 | We suggest that you stick to using default imports and exports when a module only exports a single thing (for example, a component). That’s what you get when you use `export default Button` and `import Button from './Button'`.
212 |
213 | Named exports are useful for utility modules that export several functions. A module may have at most one default export and as many named exports as you like.
214 |
215 | Learn more about ES6 modules:
216 |
217 | * [When to use the curly braces?](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281)
218 | * [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html)
219 | * [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules)
220 |
221 | ## Adding a Stylesheet
222 |
223 | This project setup uses [Webpack](https://webpack.github.io/) for handling all assets. Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to **import the CSS from the JavaScript file**:
224 |
225 | ### `Button.css`
226 |
227 | ```css
228 | .Button {
229 | padding: 20px;
230 | }
231 | ```
232 |
233 | ### `Button.js`
234 |
235 | ```js
236 | import React, { Component } from 'react';
237 | import './Button.css'; // Tell Webpack that Button.js uses these styles
238 |
239 | class Button extends Component {
240 | render() {
241 | // You can use them as regular CSS styles
242 | return ;
243 | }
244 | }
245 | ```
246 |
247 | **This is not required for React** but many people find this feature convenient. You can read about the benefits of this approach [here](https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b). However you should be aware that this makes your code less portable to other build tools and environments than Webpack.
248 |
249 | In development, expressing dependencies this way allows your styles to be reloaded on the fly as you edit them. In production, all CSS files will be concatenated into a single minified `.css` file in the build output.
250 |
251 | If you are concerned about using Webpack-specific semantics, you can put all your CSS right into `src/index.css`. It would still be imported from `src/index.js`, but you could always remove that import if you later migrate to a different build tool.
252 |
253 | ## Post-Processing CSS
254 |
255 | This project setup minifies your CSS and adds vendor prefixes to it automatically through [Autoprefixer](https://github.com/postcss/autoprefixer) so you don’t need to worry about it.
256 |
257 | For example, this:
258 |
259 | ```css
260 | .App {
261 | display: flex;
262 | flex-direction: row;
263 | align-items: center;
264 | }
265 | ```
266 |
267 | becomes this:
268 |
269 | ```css
270 | .App {
271 | display: -webkit-box;
272 | display: -ms-flexbox;
273 | display: flex;
274 | -webkit-box-orient: horizontal;
275 | -webkit-box-direction: normal;
276 | -ms-flex-direction: row;
277 | flex-direction: row;
278 | -webkit-box-align: center;
279 | -ms-flex-align: center;
280 | align-items: center;
281 | }
282 | ```
283 |
284 | There is currently no support for preprocessors such as Less, or for sharing variables across CSS files.
285 |
286 | ## Adding Images and Fonts
287 |
288 | With Webpack, using static assets like images and fonts works similarly to CSS.
289 |
290 | You can **`import` an image right in a JavaScript module**. This tells Webpack to include that image in the bundle. Unlike CSS imports, importing an image or a font gives you a string value. This value is the final image path you can reference in your code.
291 |
292 | Here is an example:
293 |
294 | ```js
295 | import React from 'react';
296 | import logo from './logo.png'; // Tell Webpack this JS file uses this image
297 |
298 | console.log(logo); // /logo.84287d09.png
299 |
300 | function Header() {
301 | // Import result is the URL of your image
302 | return ;
303 | }
304 |
305 | export default function Header;
306 | ```
307 |
308 | This works in CSS too:
309 |
310 | ```css
311 | .Logo {
312 | background-image: url(./logo.png);
313 | }
314 | ```
315 |
316 | Webpack finds all relative module references in CSS (they start with `./`) and replaces them with the final paths from the compiled bundle. If you make a typo or accidentally delete an important file, you will see a compilation error, just like when you import a non-existent JavaScript module. The final filenames in the compiled bundle are generated by Webpack from content hashes. If the file content changes in the future, Webpack will give it a different name in production so you don’t need to worry about long-term caching of assets.
317 |
318 | Please be advised that this is also a custom feature of Webpack.
319 |
320 | **It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images). However it may not be portable to some other environments, such as Node.js and Browserify. If you prefer to reference static assets in a more traditional way outside the module system, please let us know [in this issue](https://github.com/facebookincubator/create-react-app/issues/28), and we will consider support for this.
321 |
322 | ## Adding Bootstrap
323 |
324 | You don’t have to use [React Bootstrap](https://react-bootstrap.github.io) together with React but it is a popular library for integrating Bootstrap with React apps. If you need it, you can integrate it with Create React App by following these steps:
325 |
326 | Install React Bootstrap and Bootstrap from NPM. React Bootstrap does not include Bootstrap CSS so this needs to be installed as well:
327 |
328 | ```
329 | npm install react-bootstrap --save
330 | npm install bootstrap@3 --save
331 | ```
332 |
333 | Import Bootstrap CSS and optionally Bootstrap theme CSS in the ```src/index.js``` file:
334 |
335 | ```js
336 | import 'bootstrap/dist/css/bootstrap.css';
337 | import 'bootstrap/dist/css/bootstrap-theme.css';
338 | ```
339 |
340 | Import required React Bootstrap components within ```src/App.js``` file or your custom component files:
341 |
342 | ```js
343 | import { Navbar, Jumbotron, Button } from 'react-bootstrap';
344 | ```
345 |
346 | Now you are ready to use the imported React Bootstrap components within your component hierarchy defined in the render method. Here is an example [`App.js`](https://gist.githubusercontent.com/gaearon/85d8c067f6af1e56277c82d19fd4da7b/raw/6158dd991b67284e9fc8d70b9d973efe87659d72/App.js) redone using React Bootstrap.
347 |
348 | ## Adding Flow
349 |
350 | Flow typing is currently [not supported out of the box](https://github.com/facebookincubator/create-react-app/issues/72) with the default `.flowconfig` generated by Flow. If you run it, you might get errors like this:
351 |
352 | ```js
353 | node_modules/fbjs/lib/Deferred.js.flow:60
354 | 60: Promise.prototype.done.apply(this._promise, arguments);
355 | ^^^^ property `done`. Property not found in
356 | 495: declare class Promise<+R> {
357 | ^ Promise. See lib: /private/tmp/flow/flowlib_34952d31/core.js:495
358 |
359 | node_modules/fbjs/lib/shallowEqual.js.flow:29
360 | 29: return x !== 0 || 1 / (x: $FlowIssue) === 1 / (y: $FlowIssue);
361 | ^^^^^^^^^^ identifier `$FlowIssue`. Could not resolve name
362 |
363 | src/App.js:3
364 | 3: import logo from './logo.svg';
365 | ^^^^^^^^^^^^ ./logo.svg. Required module not found
366 |
367 | src/App.js:4
368 | 4: import './App.css';
369 | ^^^^^^^^^^^ ./App.css. Required module not found
370 |
371 | src/index.js:5
372 | 5: import './index.css';
373 | ^^^^^^^^^^^^^ ./index.css. Required module not found
374 | ```
375 |
376 | To fix this, change your `.flowconfig` to look like this:
377 |
378 | ```ini
379 | [libs]
380 | ./node_modules/fbjs/flow/lib
381 |
382 | [options]
383 | esproposal.class_static_fields=enable
384 | esproposal.class_instance_fields=enable
385 |
386 | module.name_mapper='^\(.*\)\.css$' -> 'react-scripts/config/flow/css'
387 | module.name_mapper='^\(.*\)\.\(jpg\|png\|gif\|eot\|otf\|webp\|svg\|ttf\|woff\|woff2\|mp4\|webm\)$' -> 'react-scripts/config/flow/file'
388 |
389 | suppress_type=$FlowIssue
390 | suppress_type=$FlowFixMe
391 | ```
392 |
393 | Re-run flow, and you shouldn’t get any extra issues.
394 |
395 | If you later `eject`, you’ll need to replace `react-scripts` references with the `` placeholder, for example:
396 |
397 | ```ini
398 | module.name_mapper='^\(.*\)\.css$' -> '/config/flow/css'
399 | module.name_mapper='^\(.*\)\.\(jpg\|png\|gif\|eot\|otf\|webp\|svg\|ttf\|woff\|woff2\|mp4\|webm\)$' -> '/config/flow/file'
400 | ```
401 |
402 | We will consider integrating more tightly with Flow in the future so that you don’t have to do this.
403 |
404 | ## Adding Custom Environment Variables
405 |
406 | >Note: this feature is available with `react-scripts@0.2.3` and higher.
407 |
408 | Your project can consume variables declared in your environment as if they were declared locally in your JS files. By
409 | default you will have `NODE_ENV` defined for you, and any other environment variables starting with
410 | `REACT_APP_`. These environment variables will be defined for you on `process.env`. For example, having an environment
411 | variable named `REACT_APP_SECRET_CODE` will be exposed in your JS as `process.env.REACT_APP_SECRET_CODE`, in addition
412 | to `process.env.NODE_ENV`.
413 |
414 | These environment variables can be useful for displaying information conditionally based on where the project is
415 | deployed or consuming sensitive data that lives outside of version control.
416 |
417 | First, you need to have environment variables defined, which can vary between OSes. For example, let's say you wanted to
418 | consume a secret defined in the environment inside a `