X Tutup
Skip to content

Commit ce63dd4

Browse files
committed
merge with gh-pages branch
2 parents a773433 + 5ab536e commit ce63dd4

File tree

16 files changed

+237
-6
lines changed

16 files changed

+237
-6
lines changed

ES6.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# ES6 Project Update
2+
3+
The project is converted to ES6 and the code is added to the [master branch](https://github.com/parkjs814/AlgorithmVisualizer/tree/master).
4+
It will stay there until it reaches the same level as`gh-pages`, at which point the master branch will become the default branch.
5+
6+
## Build System
7+
8+
The new app uses [gulp](http://gulpjs.com/) to:
9+
10+
- combine all individual modules into a single file
11+
- transpile ES6 code to ES5 with [babel.js](http://babeljs.io/)
12+
- minimize JS and CSS code
13+
- generate source maps
14+
- add vendor prefixer to the css
15+
- provide a server with live-reload
16+
17+
## Installation
18+
19+
```bash
20+
# install gulp globally so you can run it from the command line
21+
npm install -g gulp-cli
22+
23+
# install all dependencies
24+
npm install
25+
26+
# run gulp to build all the files start the livereload server on http://localhost:8080
27+
gulp
28+
```
29+
30+
## Changes Summary
31+
32+
*Note:* Although no linter is added as of yet, the code closely follows the conventions from [Airbnb's Javascript style guide](https://github.com/airbnb/javascript)
33+
34+
### [js/index.js](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js)
35+
36+
The app entry point is [`js/index.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js).
37+
It performs the initial application setup (loads the app when jQuery loads, loads the initial data from the server etc.)
38+
39+
### [js/app/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/app)
40+
41+
The main application object is [`js/app/index.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/app/index.js), which holds the necessary global application state flags and application level methods.
42+
It is [extended once the app loads in `index.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js#L30) with the contents of [`app/constructor`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/app/constructor.js) and [`app/cache`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/app/cache.js).
43+
This means that from here on now, any file that does `require(/* path to js/app */)` is getting that populated object since calls to `require` are cached.
44+
45+
### [js/dom/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/dom)
46+
47+
The `js/dom` folder holds all the code interacting with the DOM (go figure 😜).
48+
The code is split into:
49+
50+
- "static" methods that are used everywhere (such as adding algorithm info to the DOM) and,
51+
- setup code which is called within the `app/constructor`, after the DOM is ready, to initialize all the elements with their contents and listeners.
52+
53+
### [js/editor/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/editor)
54+
55+
The `js/editor` folder holds the code to create and execute code in the ace editor.
56+
57+
### [js/module/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/module)
58+
59+
The `js/module` folder holds all the tracers and their variations and it is essentially the same as [`js/module`](https://github.com/parkjs814/AlgorithmVisualizer/tree/gh-pages/js/module) on the `gh-pages` branch.
60+
The only changes are present in `js/tracer.js` where the code is converted to ES6.
61+
All the modules are exported together and then "required" inside the entry point [`js/index.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js) where they are [attached to the global `window` object](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js#L33) so [`eval` can use them](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/editor/executor.js#L7) when executing code in the code editor.
62+
63+
### [js/server/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/server)
64+
65+
The `js/server` folder holds all the code to load data from the server and utilizes promises from [RSVP.js](https://github.com/tildeio/rsvp.js/).
66+
In [`js/server/ajax`](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/server/ajax) are some helper methods to make requesting from the server a little easier.
67+
The main method is [`js/server/ajax/request.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/server/ajax/request.js) that is used by all other methods to call `$.ajax` with certain options and set/reset the global `isLoading` flag for every request.
68+
69+
### [js/trace_manager/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/server/ajax)
70+
71+
The `js/tracer_manager` folder holds the same logic as the [original `tracer_manager`](https://github.com/parkjs814/AlgorithmVisualizer/blob/gh-pages/js/tracer_manager.js) from `gh-pages` branch converted to ES6 and split into modules based on functionality.
72+
73+
### [js/utils/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/utils)
74+
75+
The `utils` folder holds a few helper methods that are used everywhere such as building the strings for algorithm and file directories.
76+
77+
## Remaining updates
78+
79+
- Any algorithms added since ES6 updates were pushed to master.
80+
- The following pull-request code is still missing from the ES6 project and needs to be added before a full project update can be made:
81+
82+
- https://github.com/parkjs814/AlgorithmVisualizer/pull/97
83+
- https://github.com/parkjs814/AlgorithmVisualizer/pull/101
84+
- https://github.com/parkjs814/AlgorithmVisualizer/pull/102

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#### [Oh yeah, ES6 update is here 😎](https://github.com/parkjs814/AlgorithmVisualizer/blob/gh-pages/ES6.md)
2+
13
# Algorithm Visualizer
24

35
[![Join the chat at https://gitter.im/parkjs814/AlgorithmVisualizer](https://badges.gitter.im/parkjs814/AlgorithmVisualizer.svg)](https://gitter.im/parkjs814/AlgorithmVisualizer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

algorithm/category.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"page_rank": "PageRank Algorithm"
1313
}
1414
},
15+
"number_theory": {
16+
"name": "Number Theory",
17+
"list": {
18+
"seive_of_erathrones": "Seive of Erathrones"
19+
}
20+
},
1521
"cryptography": {
1622
"name": "Cryptography",
1723
"list": {
@@ -65,7 +71,9 @@
6571
"max_sum_path": "Maximum Sum Path",
6672
"sliding_window": "Sliding Window",
6773
"integer_partition": "Integer Partition",
68-
"ugly_numbers": "Ugly Numbers"
74+
"ugly_numbers": "Ugly Numbers",
75+
"pascal_triangle": "Pascal's Trangle",
76+
"catalan_number": "Catalan Number"
6977
}
7078
},
7179
"greedy": {

algorithm/cryptography/caesar_cipher/basic/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var alphabetMap = alphabet.split('').reduce(function(map, curr, idx) {
99
return map;
1010
}, {});
1111

12-
var logger = new LogTracer();
1312
var encryptTracer = new Array1DTracer('Encryption');
1413
var decryptTracer = new Array1DTracer('Decryption');
14+
var logger = new LogTracer();
1515

1616
encryptTracer._setData(string);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
A[0] = 1;
2+
tracer._notify ( 0, A[0] )._wait();
3+
tracer._denotify ( 0 );
4+
A[1] = 1;
5+
tracer._notify ( 1, A[1] )._wait();
6+
tracer._denotify ( 1 );
7+
8+
for (var i = 2; i <= N; i++) {
9+
for (var j = 0; j < i; j++) {
10+
A[i] += A[j] * A[i-j-1];
11+
tracer._select( j )._wait();
12+
tracer._select( i - j -1 )._wait();
13+
tracer._notify( i, A[i])._wait();
14+
tracer._deselect( j );
15+
tracer._deselect( i - j - 1 );
16+
tracer._denotify( i );
17+
}
18+
}
19+
20+
logger._print ( ' The ' + N + 'th Catalan Number is ' + A[N] );
21+
tracer._select( N )._wait();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var N = 10;
2+
var A = new Array ( N+1 );
3+
for (var i = N; i >= 0; i--) {
4+
A[i] = 0;
5+
}
6+
7+
var tracer = new Array1DTracer( ' Catalan Numbers ')._setData( A );
8+
var logger = new LogTracer();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"Catalan Number": " In combinatorial mathematics, the Catalan numbers form a sequence of natural numbers that occur in various counting problems, often involving recursively-defined objects.The Catalan numbers on nonnegative integers n are a set of numbers that arise in tree enumeration problems of the type, 'In how many ways can a regular n-gon be divided into n-2 triangles if different orientations are counted separately?' (Euler's polygon division problem).",
3+
"Applications": [
4+
"The number of ways to stack coins on a bottom row that consists of n consecutive coins in a plane, such that no coins are allowed to be put on the two sides of the bottom coins and every additional coin must be above two other coins, is the nth Catalan number",
5+
"The number of ways to group a string of n pairs of parentheses, such that each open parenthesis has a matching closed parenthesis, is the nth Catalan number",
6+
"The number of ways to cut an n+2-sided convex polygon in a plane into triangles by connecting vertices with straight, non-intersecting lines is the nth Catalan number. This is the application in which Euler was interested."
7+
],
8+
"Complexity": {
9+
"time": " O(N<sup>2</sup>)",
10+
"space": "O(N)"
11+
},
12+
"References": [
13+
"<a href='https://en.wikipedia.org/wiki/Catalan_number'>Wikipedia</a>",
14+
"<a href='http://oldweb.sbc.edu/sites/default/files/Honors/XiaotongJiang.July20_0.pdf'>Sweet Briar College"
15+
],
16+
"files": {
17+
"catalan_number": "Catalan Number"
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"Pascal's Triangle": " Pascal's triangle is a triangular array of the binomial coefficients.",
3+
"Applications": [
4+
"Binomial Expansion",
5+
"Probability"
6+
],
7+
"Complexity": {
8+
"time": " O(N<sup>2</sup>)",
9+
"space": "O(N<sup>2</sup>)"
10+
},
11+
"References": [
12+
"<a href='https://en.wikipedia.org/wiki/Pascal%27s_triangle'>Wikipedia</a>"
13+
],
14+
"files": {
15+
"pascal_triangle": "Pascal's Triangle"
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
for ( var i = 0; i < N; i++ ) {
2+
for ( var j = 0; j <= i; j++ ) {
3+
if( j === i || j === 0 ) { // First and last values in every row are 1
4+
A[i][j] = 1;
5+
6+
tracer._notify( i, j, A[i][j])._wait();
7+
tracer._denotify( i, j);
8+
} else { // Other values are sum of values just above and left of above
9+
tracer._select( i-1, j-1)._wait();
10+
tracer._select( i-1, j)._wait();
11+
12+
A[i][j] = A[i-1][j-1] + A[i-1][j];
13+
14+
tracer._notify( i, j, A[i][j])._wait();
15+
tracer._denotify( i, j);
16+
tracer._deselect( i-1, j-1);
17+
tracer._deselect( i-1, j);
18+
}
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var N = 9;
2+
var A = new Array (N);
3+
for (var i = N - 1; i >= 0; i--) {
4+
A[i] = new Array (N);
5+
}
6+
7+
for (var i = N - 1; i >= 0; i--) {
8+
for (var j = N - 1; j >= 0; j--) {
9+
A[i][j] = ' ';
10+
}
11+
}
12+
13+
var tracer = new Array2DTracer ('Pascal\'s Triangle')._setData(A);

0 commit comments

Comments
 (0)
X Tutup