Skip to content

eslint update + fixed new js lint issues #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"prefer-destructuring": ["error", {"object": true, "array": false}],
"padded-blocks": 0,
"no-sparse-arrays": 0,
"array-bracket-spacing": 0
"array-bracket-spacing": 0,
"import/no-named-as-default": 0,
"implicit-arrow-linebreak": 0
}
}
2,033 changes: 1,562 additions & 471 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"lint:js": "eslint src/js && eslint test/js",
"lint:ts": "tslint -c tslint.json 'src/ts/**/*.ts' && tslint -c tslint.json 'test/ts/**/*.ts'",
"lint": "npm run lint:js && npm run lint:ts",
"eslintFix": "eslint src/js --fix && eslint test/js --fix",
"test:js": "mocha --compilers js:babel-core/register ./test/js --recursive --reporter mochawesome",
"test:ts": "mocha -r ts-node/register ./test/ts/**/*.spec.ts ./test/ts/**/**/*.spec.ts --recursive",
"test": "npm run test:js && npm run test:ts",
Expand Down Expand Up @@ -58,15 +59,15 @@
"@types/mocha": "^5.0.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.2",
"babel-loader": "^7.1.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.5",
"babel-plugin-add-module-exports": "^1.0.0",
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
"babel-preset-env": "^1.7.0",
"chai": "^4.1.2",
"codecov": "^3.2.0",
"eslint": "^4.18.2",
"eslint-config-airbnb-base": "^12.1.0",
"eslint": "^5.15.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.16.0",
"istanbul": "^v1.1.0-alpha.1",
"mocha": "^5.0.4",
Expand Down
6 changes: 3 additions & 3 deletions src/js/algorithms/backtracking/sudoku-solver.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ function usedInBox(matrix, boxStartRow, boxStartCol, num) {

function isSafe(matrix, row, col, num) {
return (
!usedInRow(matrix, row, num) &&
!usedInCol(matrix, col, num) &&
!usedInBox(matrix, row - (row % 3), col - (col % 3), num)
!usedInRow(matrix, row, num)
&& !usedInCol(matrix, col, num)
&& !usedInBox(matrix, row - (row % 3), col - (col % 3), num)
);
}
function solveSudoku(matrix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ export function matrixChainOrder(p) {
printOptimalParenthesis(s, 1, n - 1);
return m[1][n - 1];
}

6 changes: 3 additions & 3 deletions src/js/algorithms/dynamic-programing/min-coin-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export function minCoinChange(coins, amount) {
newMin = makeChange(newAmount);
}
if (
newAmount >= 0 &&
(newMin.length < min.length - 1 || !min.length) &&
(newMin.length || !newAmount)
newAmount >= 0
&& (newMin.length < min.length - 1 || !min.length)
&& (newMin.length || !newAmount)
) {
min = [coin].concat(newMin);
// console.log('new Min ' + min + ' for ' + amount);
Expand Down
4 changes: 2 additions & 2 deletions src/js/algorithms/greedy/matrix-chain-multiplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export function matrixChainOrder(p, i = 1, j = p.length - 1) {
}
let min = Number.MAX_SAFE_INTEGER;
for (let k = i; k < j; k++) {
const count =
matrixChainOrder(p, i, k) + matrixChainOrder(p, k + 1, j) + ((p[i - 1] * p[k]) * p[j]);
const count = matrixChainOrder(p, i, k)
+ matrixChainOrder(p, k + 1, j) + ((p[i - 1] * p[k]) * p[j]);
if (count < min) {
min = count;
}
Expand Down
6 changes: 3 additions & 3 deletions src/js/algorithms/search/interpolation-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export function interpolationSearch(
let position = -1;
let delta = -1;
while (
low <= high &&
biggerEquals(value, array[low], compareFn) &&
lesserEquals(value, array[high], compareFn)
low <= high
&& biggerEquals(value, array[low], compareFn)
&& lesserEquals(value, array[high], compareFn)
) {
delta = diffFn(value, array[low]) / diffFn(array[high], array[low]);
position = low + Math.floor((high - low) * delta);
Expand Down
19 changes: 14 additions & 5 deletions src/js/data-structures/avl-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export default class AVLTree extends BinarySearchTree {
this.compareFn = compareFn;
this.root = null;
}

getNodeHeight(node) {
if (node == null) {
return -1;
}
return Math.max(this.getNodeHeight(node.left), this.getNodeHeight(node.right)) + 1;
}

/**
* Left left case: rotate right
*
Expand All @@ -39,6 +41,7 @@ export default class AVLTree extends BinarySearchTree {
tmp.right = node;
return tmp;
}

/**
* Right right case: rotate left
*
Expand All @@ -56,6 +59,7 @@ export default class AVLTree extends BinarySearchTree {
tmp.left = node;
return tmp;
}

/**
* Left right case: rotate left then right
* @param node Node<T>
Expand All @@ -64,6 +68,7 @@ export default class AVLTree extends BinarySearchTree {
node.left = this.rotationRR(node.left);
return this.rotationLL(node);
}

/**
* Right left case: rotate right then left
* @param node Node<T>
Expand All @@ -72,6 +77,7 @@ export default class AVLTree extends BinarySearchTree {
node.right = this.rotationLL(node.right);
return this.rotationRR(node);
}

getBalanceFactor(node) {
const heightDifference = this.getNodeHeight(node.left) - this.getNodeHeight(node.right);
switch (heightDifference) {
Expand All @@ -87,13 +93,15 @@ export default class AVLTree extends BinarySearchTree {
return BalanceFactor.BALANCED;
}
}

insert(key) {
this.root = this.insertNode(this.root, key);
}

insertNode(node, key) {
if (node == null) {
return new Node(key);
} else if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
} if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
node.left = this.insertNode(node.left, key);
} else if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
node.right = this.insertNode(node.right, key);
Expand Down Expand Up @@ -122,6 +130,7 @@ export default class AVLTree extends BinarySearchTree {
}
return node;
}

removeNode(node, key) {
node = super.removeNode(node, key); // {1}
if (node == null) {
Expand All @@ -132,8 +141,8 @@ export default class AVLTree extends BinarySearchTree {
if (balanceFactor === BalanceFactor.UNBALANCED_LEFT) {
// Left left case
if (
this.getBalanceFactor(node.left) === BalanceFactor.BALANCED ||
this.getBalanceFactor(node.left) === BalanceFactor.SLIGHTLY_UNBALANCED_LEFT
this.getBalanceFactor(node.left) === BalanceFactor.BALANCED
|| this.getBalanceFactor(node.left) === BalanceFactor.SLIGHTLY_UNBALANCED_LEFT
) {
return this.rotationLL(node);
}
Expand All @@ -145,8 +154,8 @@ export default class AVLTree extends BinarySearchTree {
if (balanceFactor === BalanceFactor.UNBALANCED_RIGHT) {
// Right right case
if (
this.getBalanceFactor(node.right) === BalanceFactor.BALANCED ||
this.getBalanceFactor(node.right) === BalanceFactor.SLIGHTLY_UNBALANCED_RIGHT
this.getBalanceFactor(node.right) === BalanceFactor.BALANCED
|| this.getBalanceFactor(node.right) === BalanceFactor.SLIGHTLY_UNBALANCED_RIGHT
) {
return this.rotationRR(node);
}
Expand Down
23 changes: 20 additions & 3 deletions src/js/data-structures/binary-search-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class BinarySearchTree {
this.compareFn = compareFn;
this.root = undefined;
}

insert(key) {
// special case: first key
if (this.root == null) {
Expand All @@ -14,6 +15,7 @@ export default class BinarySearchTree {
this.insertNode(this.root, key);
}
}

insertNode(node, key) {
if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
if (node.left == null) {
Expand All @@ -27,84 +29,99 @@ export default class BinarySearchTree {
this.insertNode(node.right, key);
}
}

getRoot() {
return this.root;
}

search(key) {
return this.searchNode(this.root, key);
}

searchNode(node, key) {
if (node == null) {
return false;
}
if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
return this.searchNode(node.left, key);
} else if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
} if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
return this.searchNode(node.right, key);
}
return true;
}

inOrderTraverse(callback) {
this.inOrderTraverseNode(this.root, callback);
}

inOrderTraverseNode(node, callback) {
if (node != null) {
this.inOrderTraverseNode(node.left, callback);
callback(node.key);
this.inOrderTraverseNode(node.right, callback);
}
}

preOrderTraverse(callback) {
this.preOrderTraverseNode(this.root, callback);
}

preOrderTraverseNode(node, callback) {
if (node != null) {
callback(node.key);
this.preOrderTraverseNode(node.left, callback);
this.preOrderTraverseNode(node.right, callback);
}
}

postOrderTraverse(callback) {
this.postOrderTraverseNode(this.root, callback);
}

postOrderTraverseNode(node, callback) {
if (node != null) {
this.postOrderTraverseNode(node.left, callback);
this.postOrderTraverseNode(node.right, callback);
callback(node.key);
}
}

min() {
return this.minNode(this.root);
}

minNode(node) {
let current = node;
while (current != null && current.left != null) {
current = current.left;
}
return current;
}

max() {
return this.maxNode(this.root);
}

maxNode(node) {
let current = node;
while (current != null && current.right != null) {
current = current.right;
}
return current;
}

remove(key) {
this.root = this.removeNode(this.root, key);
}

removeNode(node, key) {
if (node == null) {
return undefined;
}
if (this.compareFn(key, node.key) === Compare.LESS_THAN) {
node.left = this.removeNode(node.left, key);
return node;
} else if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
} if (this.compareFn(key, node.key) === Compare.BIGGER_THAN) {
node.right = this.removeNode(node.right, key);
return node;
}
Expand All @@ -122,7 +139,7 @@ export default class BinarySearchTree {
if (node.left == null) {
node = node.right;
return node;
} else if (node.right == null) {
} if (node.right == null) {
node = node.left;
return node;
}
Expand Down
3 changes: 3 additions & 0 deletions src/js/data-structures/circular-linked-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class CircularLinkedList extends LinkedList {
constructor(equalsFn = defaultEquals) {
super(equalsFn);
}

push(element) {
const node = new Node(element);
let current;
Expand All @@ -19,6 +20,7 @@ export default class CircularLinkedList extends LinkedList {
node.next = this.head;
this.count++;
}

insert(element, index) {
if (index >= 0 && index <= this.count) {
const node = new Node(element);
Expand All @@ -45,6 +47,7 @@ export default class CircularLinkedList extends LinkedList {
}
return false;
}

removeAt(index) {
if (index >= 0 && index < this.count) {
let current = this.head;
Expand Down
Loading