Skip to content

Commit cae3560

Browse files
authored
Merge pull request #1 from loiane/master
Merging changes from head/master to my github base/master directly.
2 parents 44cdb55 + c1c374f commit cae3560

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+6506
-6281
lines changed

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"prefer-destructuring": ["error", {"object": true, "array": false}],
3333
"padded-blocks": 0,
3434
"no-sparse-arrays": 0,
35-
"array-bracket-spacing": 0
35+
"array-bracket-spacing": 0,
36+
"import/no-named-as-default": 0,
37+
"implicit-arrow-linebreak": 0
3638
}
3739
}

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Learning JavaScript Data Structures and Algorithms
22
====================================
33

4-
[![Build Status](https://travis-ci.org/loiane/javascript-datastructures-algorithms.svg?branch=third-edition)](https://travis-ci.org/loiane/javascript-datastructures-algorithms)
4+
[![Build Status](https://travis-ci.org/loiane/javascript-datastructures-algorithms.svg?branch=master)](https://travis-ci.org/loiane/javascript-datastructures-algorithms)
55
[![codecov](https://codecov.io/gh/loiane/javascript-datastructures-algorithms/branch/master/graph/badge.svg)](https://codecov.io/gh/loiane/javascript-datastructures-algorithms)
66
[![devDependencies Status](https://david-dm.org/loiane/javascript-datastructures-algorithms/dev-status.svg)](https://david-dm.org/loiane/javascript-datastructures-algorithms?type=dev)
77
[![dependencies Status](https://david-dm.org/loiane/javascript-datastructures-algorithms/status.svg)](https://david-dm.org/loiane/javascript-datastructures-algorithms)
@@ -82,7 +82,7 @@ Happy Coding!
8282

8383
| 1st edition | 2nd edition | 3rd edition |
8484
| ------------- |:-------------:|:-------------:|
85-
| ![1st edition](https://d1ldz4te4covpm.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/4874OS_Learning%20JavaScript%20Data%20Structures%20and%20Algorithms.jpg) | ![2nd edition](https://d255esdrn735hr.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/5493OS_5348_Learning%20JavaScript%20Data%20Structures%20and%20Algorithms,%20Second%20Edition.jpg) | ![3rd edition](https://d1ldz4te4covpm.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/B09377.png) |
85+
| ![1st edition](https://images-na.ssl-images-amazon.com/images/I/51xXGv7QlBL._SX403_BO1,204,203,200_.jpg) | ![2nd edition](https://images-na.ssl-images-amazon.com/images/I/51PWJ%2BoKc2L._SX403_BO1,204,203,200_.jpg) | ![3rd edition](https://images-na.ssl-images-amazon.com/images/I/41oSXp3VztL._SX404_BO1,204,203,200_.jpg) |
8686
| [Book link](http://amzn.to/1Y1OWPx)| [Book link](http://amzn.to/1TSkcA1)| [Book link](http://a.co/cbMlYmJ)|
8787

8888
Book link - first edition:
@@ -100,6 +100,8 @@ Book link - second edition:
100100
Book link - third edition:
101101
- [Packt](https://www.packtpub.com/web-development/learning-javascript-data-structures-and-algorithms-third-edition)
102102
- [Amazon](http://a.co/cbMlYmJ)
103+
- [Chinese version](http://www.ituring.com.cn/book/2653)
104+
- [Brazilian Portuguese version](https://novatec.com.br/livros/estruturas-de-dados-algoritmos-em-javascript-2ed/)
103105

104106
### Found an issue or have a question?
105107

package-lock.json

Lines changed: 6267 additions & 6197 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lint:js": "eslint src/js && eslint test/js",
2222
"lint:ts": "tslint -c tslint.json 'src/ts/**/*.ts' && tslint -c tslint.json 'test/ts/**/*.ts'",
2323
"lint": "npm run lint:js && npm run lint:ts",
24+
"eslintFix": "eslint src/js --fix && eslint test/js --fix",
2425
"test:js": "mocha --compilers js:babel-core/register ./test/js --recursive --reporter mochawesome",
2526
"test:ts": "mocha -r ts-node/register ./test/ts/**/*.spec.ts ./test/ts/**/**/*.spec.ts --recursive",
2627
"test": "npm run test:js && npm run test:ts",
@@ -57,27 +58,27 @@
5758
"@types/chai": "^4.1.2",
5859
"@types/mocha": "^5.0.0",
5960
"babel-cli": "^6.26.0",
60-
"babel-core": "^6.26.0",
61-
"babel-eslint": "^8.2.2",
62-
"babel-loader": "^7.1.4",
63-
"babel-plugin-add-module-exports": "^0.2.1",
61+
"babel-core": "^6.26.3",
62+
"babel-eslint": "^10.0.1",
63+
"babel-loader": "^8.0.5",
64+
"babel-plugin-add-module-exports": "^1.0.0",
6465
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
65-
"babel-preset-env": "^1.6.1",
66+
"babel-preset-env": "^1.7.0",
6667
"chai": "^4.1.2",
67-
"codecov": "^3.0.0",
68-
"eslint": "^4.18.2",
69-
"eslint-config-airbnb-base": "^12.1.0",
70-
"eslint-plugin-import": "^2.9.0",
68+
"codecov": "^3.2.0",
69+
"eslint": "^5.15.1",
70+
"eslint-config-airbnb-base": "^13.1.0",
71+
"eslint-plugin-import": "^2.16.0",
7172
"istanbul": "^v1.1.0-alpha.1",
7273
"mocha": "^5.0.4",
7374
"mochawesome": "^3.0.2",
7475
"nyc": "11.7.2",
75-
"ts-node": "^5.0.1",
76-
"tslint": "^5.9.1",
77-
"typescript": "^2.7.2",
78-
"webpack": "^4.1.1",
79-
"webpack-cli": "2.1.1",
80-
"yargs": "^11.0.0"
76+
"ts-node": "8.0.3",
77+
"tslint": "5.14.0",
78+
"typescript": "3.3.3333",
79+
"webpack": "^4.29.6",
80+
"webpack-cli": "3.3.0",
81+
"yargs": "13.2.2"
8182
},
8283
"dependencies": {
8384
"http-server": "^0.11.1"

src/js/algorithms/backtracking/sudoku-solver.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ function usedInBox(matrix, boxStartRow, boxStartCol, num) {
3131

3232
function isSafe(matrix, row, col, num) {
3333
return (
34-
!usedInRow(matrix, row, num) &&
35-
!usedInCol(matrix, col, num) &&
36-
!usedInBox(matrix, row - (row % 3), col - (col % 3), num)
34+
!usedInRow(matrix, row, num)
35+
&& !usedInCol(matrix, col, num)
36+
&& !usedInBox(matrix, row - (row % 3), col - (col % 3), num)
3737
);
3838
}
3939
function solveSudoku(matrix) {

src/js/algorithms/dynamic-programing/matrix-chain-multiplication.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ export function matrixChainOrder(p) {
4343
printOptimalParenthesis(s, 1, n - 1);
4444
return m[1][n - 1];
4545
}
46-

src/js/algorithms/dynamic-programing/min-coin-change.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export function minCoinChange(coins, amount) {
1818
newMin = makeChange(newAmount);
1919
}
2020
if (
21-
newAmount >= 0 &&
22-
(newMin.length < min.length - 1 || !min.length) &&
23-
(newMin.length || !newAmount)
21+
newAmount >= 0
22+
&& (newMin.length < min.length - 1 || !min.length)
23+
&& (newMin.length || !newAmount)
2424
) {
2525
min = [coin].concat(newMin);
2626
// console.log('new Min ' + min + ' for ' + amount);

src/js/algorithms/greedy/matrix-chain-multiplication.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export function matrixChainOrder(p, i = 1, j = p.length - 1) {
44
}
55
let min = Number.MAX_SAFE_INTEGER;
66
for (let k = i; k < j; k++) {
7-
const count =
8-
matrixChainOrder(p, i, k) + matrixChainOrder(p, k + 1, j) + ((p[i - 1] * p[k]) * p[j]);
7+
const count = matrixChainOrder(p, i, k)
8+
+ matrixChainOrder(p, k + 1, j) + ((p[i - 1] * p[k]) * p[j]);
99
if (count < min) {
1010
min = count;
1111
}

src/js/algorithms/search/interpolation-search.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export function interpolationSearch(
2121
let position = -1;
2222
let delta = -1;
2323
while (
24-
low <= high &&
25-
biggerEquals(value, array[low], compareFn) &&
26-
lesserEquals(value, array[high], compareFn)
24+
low <= high
25+
&& biggerEquals(value, array[low], compareFn)
26+
&& lesserEquals(value, array[high], compareFn)
2727
) {
2828
delta = diffFn(value, array[low]) / diffFn(array[high], array[low]);
2929
position = low + Math.floor((high - low) * delta);

src/js/data-structures/avl-tree.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ export default class AVLTree extends BinarySearchTree {
1616
this.compareFn = compareFn;
1717
this.root = null;
1818
}
19+
1920
getNodeHeight(node) {
2021
if (node == null) {
2122
return -1;
2223
}
2324
return Math.max(this.getNodeHeight(node.left), this.getNodeHeight(node.right)) + 1;
2425
}
26+
2527
/**
2628
* Left left case: rotate right
2729
*
@@ -39,6 +41,7 @@ export default class AVLTree extends BinarySearchTree {
3941
tmp.right = node;
4042
return tmp;
4143
}
44+
4245
/**
4346
* Right right case: rotate left
4447
*
@@ -56,6 +59,7 @@ export default class AVLTree extends BinarySearchTree {
5659
tmp.left = node;
5760
return tmp;
5861
}
62+
5963
/**
6064
* Left right case: rotate left then right
6165
* @param node Node<T>
@@ -64,6 +68,7 @@ export default class AVLTree extends BinarySearchTree {
6468
node.left = this.rotationRR(node.left);
6569
return this.rotationLL(node);
6670
}
71+
6772
/**
6873
* Right left case: rotate right then left
6974
* @param node Node<T>
@@ -72,6 +77,7 @@ export default class AVLTree extends BinarySearchTree {
7277
node.right = this.rotationLL(node.right);
7378
return this.rotationRR(node);
7479
}
80+
7581
getBalanceFactor(node) {
7682
const heightDifference = this.getNodeHeight(node.left) - this.getNodeHeight(node.right);
7783
switch (heightDifference) {
@@ -87,13 +93,15 @@ export default class AVLTree extends BinarySearchTree {
8793
return BalanceFactor.BALANCED;
8894
}
8995
}
96+
9097
insert(key) {
9198
this.root = this.insertNode(this.root, key);
9299
}
100+
93101
insertNode(node, key) {
94102
if (node == null) {
95103
return new Node(key);
96-
} else if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
104+
} if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
97105
node.left = this.insertNode(node.left, key);
98106
} else if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
99107
node.right = this.insertNode(node.right, key);
@@ -122,6 +130,7 @@ export default class AVLTree extends BinarySearchTree {
122130
}
123131
return node;
124132
}
133+
125134
removeNode(node, key) {
126135
node = super.removeNode(node, key); // {1}
127136
if (node == null) {
@@ -132,8 +141,8 @@ export default class AVLTree extends BinarySearchTree {
132141
if (balanceFactor === BalanceFactor.UNBALANCED_LEFT) {
133142
// Left left case
134143
if (
135-
this.getBalanceFactor(node.left) === BalanceFactor.BALANCED ||
136-
this.getBalanceFactor(node.left) === BalanceFactor.SLIGHTLY_UNBALANCED_LEFT
144+
this.getBalanceFactor(node.left) === BalanceFactor.BALANCED
145+
|| this.getBalanceFactor(node.left) === BalanceFactor.SLIGHTLY_UNBALANCED_LEFT
137146
) {
138147
return this.rotationLL(node);
139148
}
@@ -145,8 +154,8 @@ export default class AVLTree extends BinarySearchTree {
145154
if (balanceFactor === BalanceFactor.UNBALANCED_RIGHT) {
146155
// Right right case
147156
if (
148-
this.getBalanceFactor(node.right) === BalanceFactor.BALANCED ||
149-
this.getBalanceFactor(node.right) === BalanceFactor.SLIGHTLY_UNBALANCED_RIGHT
157+
this.getBalanceFactor(node.right) === BalanceFactor.BALANCED
158+
|| this.getBalanceFactor(node.right) === BalanceFactor.SLIGHTLY_UNBALANCED_RIGHT
150159
) {
151160
return this.rotationRR(node);
152161
}

0 commit comments

Comments
 (0)