Skip to content

Commit cfb49b3

Browse files
committed
added stack chapter 03
1 parent 3ce70a5 commit cfb49b3

File tree

15 files changed

+502
-62
lines changed

15 files changed

+502
-62
lines changed

dist/js/app.js

-18
This file was deleted.

dist/ts/app.js

-7
This file was deleted.

gulpfile.babel.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import gulp from 'gulp';
2+
import del from 'del';
3+
import babelify from 'babelify';
4+
import browserify from 'browserify';
5+
import source from 'vinyl-source-stream';
6+
import glob from 'glob';
7+
import es from 'event-stream';
8+
9+
const paths = {
10+
scriptsJs: 'lib/js/**/*.js',
11+
dist: 'dist/',
12+
distJs: 'dist/js'
13+
};
14+
15+
gulp.task('clean', fn => del(paths.dist, fn));
16+
17+
gulp.task('scripts', ['clean'], done => {
18+
glob(paths.scriptsJs, function(err, files) {
19+
if (err) done(err);
20+
21+
var tasks = files.map(function(entry) {
22+
return browserify({ entries: [entry] })
23+
.transform(babelify)
24+
.bundle()
25+
.pipe(source(entry))
26+
.pipe(gulp.dest(paths.dist));
27+
});
28+
es.merge(tasks).on('end', done);
29+
});
30+
});
31+
32+
gulp.task('default', ['scripts']);

html/chapter03/index.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script src="index.js" type="module"></script>
9+
</body>
10+
</html>

html/chapter03/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Stack from './../../lib/js/data-structures/stack.js';
2+
3+
const stack = new Stack();
4+
5+
console.log(stack);

lib/js/app.js

-5
This file was deleted.

lib/js/data-structures/stack.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const Stack = (() => {
2+
let items;
3+
class DS {
4+
constructor() {
5+
items = [];
6+
}
7+
push(element) {
8+
items.push(element);
9+
}
10+
11+
pop() {
12+
return items.pop();
13+
}
14+
15+
peek() {
16+
return items[items.length - 1];
17+
}
18+
19+
isEmpty() {
20+
return items.length === 0;
21+
}
22+
23+
size() {
24+
return items.length;
25+
}
26+
27+
clear() {
28+
items = [];
29+
}
30+
31+
toArray() {
32+
return items;
33+
}
34+
35+
toString() {
36+
return items.toString();
37+
}
38+
}
39+
return DS;
40+
})();
41+
42+
export default Stack;

lib/ts/app.ts

-5
This file was deleted.

lib/ts/data-structures/stack.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export default class Stack {
2+
private items: any[];
3+
4+
constructor() {
5+
this.items = [];
6+
}
7+
8+
push(element: any) {
9+
this.items.push(element);
10+
}
11+
12+
pop() {
13+
return this.items.pop();
14+
}
15+
16+
peek() {
17+
return this.items[this.items.length - 1];
18+
}
19+
20+
isEmpty() {
21+
return this.items.length === 0;
22+
}
23+
24+
size() {
25+
return this.items.length;
26+
}
27+
28+
clear() {
29+
this.items = [];
30+
}
31+
32+
toArray() {
33+
return this.items;
34+
}
35+
36+
toString() {
37+
return this.items.toString();
38+
}
39+
}

lib/ts/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Stack from './data-structures/stack';
2+
3+
export { Stack };

package.json

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,40 @@
1414
},
1515
"homepage": "https://github.com/loiane/javascript-datastructures-algorithms",
1616
"scripts": {
17+
"start": "gulp",
1718
"clean": "rm -rf ./dist; mkdir ./dist",
18-
"build:js": "babel lib/js --out-dir dist/js",
19+
"build:js": "babel lib/js --presets babel-preset-es2015 --out-dir dist/js",
1920
"build:ts": "tsc",
2021
"build": "npm run build:js && npm run build:ts",
21-
"test:js": "mocha --compilers js:babel-core/register --colors -R spec --recursive ./test/js",
22+
"test:js": "mocha --compilers js:babel-core/register --colors--recursive ./test/js/**/*.spec.js",
2223
"test:ts": "mocha -r ts-node/register --colors --recursive ./test/ts/**/*.spec.ts",
2324
"test": "npm run test:js && npm run test:ts",
24-
"coverage": "./node_modules/.bin/istanbul cover --include-all-sources --root ./lib/js ./node_modules/.bin/_mocha -R spec.js --recursive ./test/js -- --compilers js:babel-core/register && codecov",
25-
"serve": "http-server html",
25+
"coverage": "./node_modules/.bin/istanbul cover --include-all-sources --root ./lib/js ./node_modules/.bin/_mocha --recursive ./test/js/**/*.spec.js -- --compilers js:babel-core/register && codecov",
2626
"go": "npm run clean && npm run test && npm run build && npm run coverage"
2727
},
2828
"devDependencies": {
2929
"@types/chai": "^4.0.4",
3030
"@types/mocha": "^2.2.42",
3131
"babel-cli": "^6.26.0",
3232
"babel-core": "^6.26.0",
33-
"babel-eslint": "^7.2.3",
3433
"babel-plugin-add-module-exports": "^0.2.1",
3534
"babel-preset-es2015": "^6.24.1",
3635
"babel-preset-es2016": "^6.24.1",
3736
"babel-preset-es2017": "^6.24.1",
37+
"babelify": "^7.3.0",
38+
"browserify": "^14.4.0",
3839
"chai": "^4.1.2",
3940
"codecov": "^2.3.0",
41+
"del": "^3.0.0",
4042
"eslint": "^4.6.1",
41-
"http-server": "^0.10.0",
43+
"event-stream": "^3.3.4",
44+
"glob": "^7.1.2",
45+
"gulp": "^3.9.1",
4246
"istanbul": "^v1.1.0-alpha.1",
4347
"mocha": "^3.5.0",
4448
"ts-node": "^3.3.0",
4549
"tslint": "^5.7.0",
46-
"typescript": "^2.5.2"
50+
"typescript": "^2.5.2",
51+
"vinyl-source-stream": "^1.1.0"
4752
}
4853
}

test/js/app.spec.js

-10
This file was deleted.

0 commit comments

Comments
 (0)