Skip to content

Commit 17ad4dc

Browse files
committedJul 5, 2018
Upgrade packages.
1 parent 58640ee commit 17ad4dc

File tree

14 files changed

+1898
-745
lines changed

14 files changed

+1898
-745
lines changed
 

‎package-lock.json

+1,845-698
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636
},
3737
"homepage": "https://github.com/trekhleb/javascript-algorithms#readme",
3838
"devDependencies": {
39-
"@types/jest": "^22.2.3",
39+
"@types/jest": "^23.1.4",
4040
"babel-cli": "^6.26.0",
4141
"babel-preset-env": "^1.7.0",
4242
"codecov": "^3.0.2",
4343
"eslint": "^4.19.1",
44-
"eslint-config-airbnb": "^16.1.0",
45-
"eslint-plugin-import": "^2.12.0",
46-
"eslint-plugin-jest": "^21.15.2",
47-
"eslint-plugin-jsx-a11y": "^6.0.3",
48-
"eslint-plugin-react": "^7.8.2",
49-
"jest": "^22.4.4",
44+
"eslint-config-airbnb": "^17.0.0",
45+
"eslint-plugin-import": "^2.13.0",
46+
"eslint-plugin-jest": "^21.17.0",
47+
"eslint-plugin-jsx-a11y": "^6.1.0",
48+
"eslint-plugin-react": "^7.10.0",
49+
"jest": "^23.3.0",
5050
"pre-commit": "^1.2.2"
5151
},
5252
"dependencies": {}

‎src/algorithms/graph/prim/prim.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export default function prim(graph) {
6060
nextMinVertex.getEdges().forEach((graphEdge) => {
6161
// Add only vertices that link to unvisited nodes.
6262
if (
63-
!visitedVertices[graphEdge.startVertex.getKey()] ||
64-
!visitedVertices[graphEdge.endVertex.getKey()]
63+
!visitedVertices[graphEdge.startVertex.getKey()]
64+
|| !visitedVertices[graphEdge.endVertex.getKey()]
6565
) {
6666
edgesQueue.add(graphEdge, graphEdge.weight);
6767
}

‎src/algorithms/math/primality-test/trialDivision.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export default function trialDivision(number) {
1111
if (number <= 1) {
1212
// If number is less than one then it isn't prime by definition.
1313
return false;
14-
} else if (number <= 3) {
14+
}
15+
16+
if (number <= 3) {
1517
// All numbers from 2 to 3 are prime.
1618
return true;
1719
}

‎src/algorithms/sets/knapsack-problem/Knapsack.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ export default class Knapsack {
128128
// In this case this would mean that we need to include previous item
129129
// to the list of selected items.
130130
if (
131-
knapsackMatrix[itemIndex][weightIndex] &&
132-
knapsackMatrix[itemIndex][weightIndex] === knapsackMatrix[itemIndex - 1][weightIndex]
131+
knapsackMatrix[itemIndex][weightIndex]
132+
&& knapsackMatrix[itemIndex][weightIndex] === knapsackMatrix[itemIndex - 1][weightIndex]
133133
) {
134134
// Check if there are several items with the same weight but with the different values.
135135
// We need to add highest item in the matrix that is possible to get the highest value.
136136
const prevSumValue = knapsackMatrix[itemIndex - 1][weightIndex];
137137
const prevPrevSumValue = knapsackMatrix[itemIndex - 2][weightIndex];
138138
if (
139-
!prevSumValue ||
140-
(prevSumValue && prevPrevSumValue !== prevSumValue)
139+
!prevSumValue
140+
|| (prevSumValue && prevPrevSumValue !== prevSumValue)
141141
) {
142142
this.selectedItems.push(prevItem);
143143
}

‎src/algorithms/sorting/insertion-sort/InsertionSort.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export default class InsertionSort extends Sort {
1414
// Go and check if previous elements and greater then current one.
1515
// If this is the case then swap that elements.
1616
while (
17-
array[currentIndex - 1] !== undefined &&
18-
this.comparator.lessThan(array[currentIndex], array[currentIndex - 1])
17+
array[currentIndex - 1] !== undefined
18+
&& this.comparator.lessThan(array[currentIndex], array[currentIndex - 1])
1919
) {
2020
// Call visiting callback.
2121
this.callbacks.visitingCallback(array[currentIndex - 1]);

‎src/algorithms/sorting/radix-sort/RadixSort.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export default class RadixSort extends Sort {
1818
const numPasses = this.determineNumPasses(sortedArray);
1919

2020
for (let currentIndex = 0; currentIndex < numPasses; currentIndex += 1) {
21-
const buckets = isArrayOfNumbers ?
22-
this.placeElementsInNumberBuckets(sortedArray, currentIndex) :
23-
this.placeElementsInCharacterBuckets(sortedArray, currentIndex, numPasses);
21+
const buckets = isArrayOfNumbers
22+
? this.placeElementsInNumberBuckets(sortedArray, currentIndex)
23+
: this.placeElementsInCharacterBuckets(sortedArray, currentIndex, numPasses);
2424

2525
// Flatten buckets into sortedArray, and repeat at next index
2626
sortedArray = buckets.reduce((acc, val) => {

‎src/algorithms/string/regular-expression-matching/regularExpressionMatching.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ export default function regularExpressionMatching(string, pattern) {
8888
matchMatrix[rowIndex][columnIndex] = true;
8989
} else if (
9090
(
91-
pattern[patternIndex - 1] === string[stringIndex] ||
92-
pattern[patternIndex - 1] === ANY_CHAR
93-
) &&
94-
matchMatrix[rowIndex - 1][columnIndex] === true
91+
pattern[patternIndex - 1] === string[stringIndex]
92+
|| pattern[patternIndex - 1] === ANY_CHAR
93+
)
94+
&& matchMatrix[rowIndex - 1][columnIndex] === true
9595
) {
9696
matchMatrix[rowIndex][columnIndex] = true;
9797
} else {
9898
matchMatrix[rowIndex][columnIndex] = false;
9999
}
100100
} else if (
101-
pattern[patternIndex] === string[stringIndex] ||
102-
pattern[patternIndex] === ANY_CHAR
101+
pattern[patternIndex] === string[stringIndex]
102+
|| pattern[patternIndex] === ANY_CHAR
103103
) {
104104
/*
105105
* In case if current pattern char is the same as current string char

‎src/algorithms/string/z-algorithm/zAlgorithm.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function buildZArray(zString) {
4040
// more characters that are equal to the ones in the prefix we will expand
4141
// right Z box boundary by 3.
4242
while (
43-
zBoxRightIndex < zString.length &&
44-
zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
43+
zBoxRightIndex < zString.length
44+
&& zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
4545
) {
4646
// Expanding Z box right boundary.
4747
zBoxRightIndex += 1;
@@ -81,8 +81,8 @@ function buildZArray(zString) {
8181
// And start comparing characters one by one as we normally do for the case
8282
// when we are outside of checkbox.
8383
while (
84-
zBoxRightIndex < zString.length &&
85-
zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
84+
zBoxRightIndex < zString.length
85+
&& zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
8686
) {
8787
zBoxRightIndex += 1;
8888
}

‎src/algorithms/uncategorized/n-queens/nQueens.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ function isSafe(queensPositions, rowIndex, columnIndex) {
1616

1717
if (
1818
// Check if queen has been already placed.
19-
currentQueenPosition &&
20-
(
19+
currentQueenPosition
20+
&& (
2121
// Check if there are any queen on the same column.
22-
newQueenPosition.columnIndex === currentQueenPosition.columnIndex ||
22+
newQueenPosition.columnIndex === currentQueenPosition.columnIndex
2323
// Check if there are any queen on the same row.
24-
newQueenPosition.rowIndex === currentQueenPosition.rowIndex ||
24+
|| newQueenPosition.rowIndex === currentQueenPosition.rowIndex
2525
// Check if there are any queen on the same left diagonal.
26-
newQueenPosition.leftDiagonal === currentQueenPosition.leftDiagonal ||
26+
|| newQueenPosition.leftDiagonal === currentQueenPosition.leftDiagonal
2727
// Check if there are any queen on the same right diagonal.
28-
newQueenPosition.rightDiagonal === currentQueenPosition.rightDiagonal
28+
|| newQueenPosition.rightDiagonal === currentQueenPosition.rightDiagonal
2929
)
3030
) {
3131
// Can't place queen into current position since there are other queens that

‎src/data-structures/doubly-linked-list/DoublyLinkedList.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import DoublyLinkedListNode from './DoublyLinkedListNode';
2-
import Comparator from './../../utils/comparator/Comparator';
2+
import Comparator from '../../utils/comparator/Comparator';
33

44
export default class DoublyLinkedList {
55
/**

‎src/data-structures/doubly-linked-list/__test__/DoublyLinkedListNode.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DoublyLinkedListNode from './../DoublyLinkedListNode';
1+
import DoublyLinkedListNode from '../DoublyLinkedListNode';
22

33
describe('DoublyLinkedListNode', () => {
44
it('should create list node with value', () => {

‎src/data-structures/heap/MinHeap.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ export default class MinHeap {
164164
// If there is no parent or parent is less then node to delete then heapify down.
165165
// Otherwise heapify up.
166166
if (
167-
leftChild !== null &&
168-
(
169-
parentItem === null ||
170-
this.compare.lessThan(parentItem, this.heapContainer[indexToRemove])
167+
leftChild !== null
168+
&& (
169+
parentItem === null
170+
|| this.compare.lessThan(parentItem, this.heapContainer[indexToRemove])
171171
)
172172
) {
173173
this.heapifyDown(indexToRemove);
@@ -208,8 +208,8 @@ export default class MinHeap {
208208
let currentIndex = customStartIndex || this.heapContainer.length - 1;
209209

210210
while (
211-
this.hasParent(currentIndex) &&
212-
this.compare.lessThan(this.heapContainer[currentIndex], this.parent(currentIndex))
211+
this.hasParent(currentIndex)
212+
&& this.compare.lessThan(this.heapContainer[currentIndex], this.parent(currentIndex))
213213
) {
214214
this.swap(currentIndex, this.getParentIndex(currentIndex));
215215
currentIndex = this.getParentIndex(currentIndex);
@@ -227,8 +227,8 @@ export default class MinHeap {
227227

228228
while (this.hasLeftChild(currentIndex)) {
229229
if (
230-
this.hasRightChild(currentIndex) &&
231-
this.compare.lessThan(this.rightChild(currentIndex), this.leftChild(currentIndex))
230+
this.hasRightChild(currentIndex)
231+
&& this.compare.lessThan(this.rightChild(currentIndex), this.leftChild(currentIndex))
232232
) {
233233
nextIndex = this.getRightChildIndex(currentIndex);
234234
} else {

‎src/data-structures/tree/binary-search-tree/BinarySearchTreeNode.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
3535
this.setLeft(newNode);
3636

3737
return newNode;
38-
} else if (this.nodeValueComparator.greaterThan(value, this.value)) {
38+
}
39+
40+
if (this.nodeValueComparator.greaterThan(value, this.value)) {
3941
// Insert to the right.
4042
if (this.right) {
4143
return this.right.insert(value);
@@ -63,7 +65,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
6365
if (this.nodeValueComparator.lessThan(value, this.value) && this.left) {
6466
// Check left nodes.
6567
return this.left.find(value);
66-
} else if (this.nodeValueComparator.greaterThan(value, this.value) && this.right) {
68+
}
69+
70+
if (this.nodeValueComparator.greaterThan(value, this.value) && this.right) {
6771
// Check right nodes.
6872
return this.right.find(value);
6973
}

0 commit comments

Comments
 (0)
Please sign in to comment.