Skip to content

Commit

Permalink
Upgrade packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
trekhleb committed Jul 5, 2018
1 parent 58640ee commit 17ad4dc
Show file tree
Hide file tree
Showing 14 changed files with 1,898 additions and 745 deletions.
2,543 changes: 1,845 additions & 698 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
},
"homepage": "https://github.com/trekhleb/javascript-algorithms#readme",
"devDependencies": {
"@types/jest": "^22.2.3",
"@types/jest": "^23.1.4",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"codecov": "^3.0.2",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jest": "^21.15.2",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.8.2",
"jest": "^22.4.4",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-plugin-jsx-a11y": "^6.1.0",
"eslint-plugin-react": "^7.10.0",
"jest": "^23.3.0",
"pre-commit": "^1.2.2"
},
"dependencies": {}
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/graph/prim/prim.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export default function prim(graph) {
nextMinVertex.getEdges().forEach((graphEdge) => {
// Add only vertices that link to unvisited nodes.
if (
!visitedVertices[graphEdge.startVertex.getKey()] ||
!visitedVertices[graphEdge.endVertex.getKey()]
!visitedVertices[graphEdge.startVertex.getKey()]
|| !visitedVertices[graphEdge.endVertex.getKey()]
) {
edgesQueue.add(graphEdge, graphEdge.weight);
}
Expand Down
4 changes: 3 additions & 1 deletion src/algorithms/math/primality-test/trialDivision.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default function trialDivision(number) {
if (number <= 1) {
// If number is less than one then it isn't prime by definition.
return false;
} else if (number <= 3) {
}

if (number <= 3) {
// All numbers from 2 to 3 are prime.
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/algorithms/sets/knapsack-problem/Knapsack.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ export default class Knapsack {
// In this case this would mean that we need to include previous item
// to the list of selected items.
if (
knapsackMatrix[itemIndex][weightIndex] &&
knapsackMatrix[itemIndex][weightIndex] === knapsackMatrix[itemIndex - 1][weightIndex]
knapsackMatrix[itemIndex][weightIndex]
&& knapsackMatrix[itemIndex][weightIndex] === knapsackMatrix[itemIndex - 1][weightIndex]
) {
// Check if there are several items with the same weight but with the different values.
// We need to add highest item in the matrix that is possible to get the highest value.
const prevSumValue = knapsackMatrix[itemIndex - 1][weightIndex];
const prevPrevSumValue = knapsackMatrix[itemIndex - 2][weightIndex];
if (
!prevSumValue ||
(prevSumValue && prevPrevSumValue !== prevSumValue)
!prevSumValue
|| (prevSumValue && prevPrevSumValue !== prevSumValue)
) {
this.selectedItems.push(prevItem);
}
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/sorting/insertion-sort/InsertionSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default class InsertionSort extends Sort {
// Go and check if previous elements and greater then current one.
// If this is the case then swap that elements.
while (
array[currentIndex - 1] !== undefined &&
this.comparator.lessThan(array[currentIndex], array[currentIndex - 1])
array[currentIndex - 1] !== undefined
&& this.comparator.lessThan(array[currentIndex], array[currentIndex - 1])
) {
// Call visiting callback.
this.callbacks.visitingCallback(array[currentIndex - 1]);
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/sorting/radix-sort/RadixSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export default class RadixSort extends Sort {
const numPasses = this.determineNumPasses(sortedArray);

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

// Flatten buckets into sortedArray, and repeat at next index
sortedArray = buckets.reduce((acc, val) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ export default function regularExpressionMatching(string, pattern) {
matchMatrix[rowIndex][columnIndex] = true;
} else if (
(
pattern[patternIndex - 1] === string[stringIndex] ||
pattern[patternIndex - 1] === ANY_CHAR
) &&
matchMatrix[rowIndex - 1][columnIndex] === true
pattern[patternIndex - 1] === string[stringIndex]
|| pattern[patternIndex - 1] === ANY_CHAR
)
&& matchMatrix[rowIndex - 1][columnIndex] === true
) {
matchMatrix[rowIndex][columnIndex] = true;
} else {
matchMatrix[rowIndex][columnIndex] = false;
}
} else if (
pattern[patternIndex] === string[stringIndex] ||
pattern[patternIndex] === ANY_CHAR
pattern[patternIndex] === string[stringIndex]
|| pattern[patternIndex] === ANY_CHAR
) {
/*
* In case if current pattern char is the same as current string char
Expand Down
8 changes: 4 additions & 4 deletions src/algorithms/string/z-algorithm/zAlgorithm.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function buildZArray(zString) {
// more characters that are equal to the ones in the prefix we will expand
// right Z box boundary by 3.
while (
zBoxRightIndex < zString.length &&
zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
zBoxRightIndex < zString.length
&& zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
) {
// Expanding Z box right boundary.
zBoxRightIndex += 1;
Expand Down Expand Up @@ -81,8 +81,8 @@ function buildZArray(zString) {
// And start comparing characters one by one as we normally do for the case
// when we are outside of checkbox.
while (
zBoxRightIndex < zString.length &&
zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
zBoxRightIndex < zString.length
&& zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
) {
zBoxRightIndex += 1;
}
Expand Down
12 changes: 6 additions & 6 deletions src/algorithms/uncategorized/n-queens/nQueens.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ function isSafe(queensPositions, rowIndex, columnIndex) {

if (
// Check if queen has been already placed.
currentQueenPosition &&
(
currentQueenPosition
&& (
// Check if there are any queen on the same column.
newQueenPosition.columnIndex === currentQueenPosition.columnIndex ||
newQueenPosition.columnIndex === currentQueenPosition.columnIndex
// Check if there are any queen on the same row.
newQueenPosition.rowIndex === currentQueenPosition.rowIndex ||
|| newQueenPosition.rowIndex === currentQueenPosition.rowIndex
// Check if there are any queen on the same left diagonal.
newQueenPosition.leftDiagonal === currentQueenPosition.leftDiagonal ||
|| newQueenPosition.leftDiagonal === currentQueenPosition.leftDiagonal
// Check if there are any queen on the same right diagonal.
newQueenPosition.rightDiagonal === currentQueenPosition.rightDiagonal
|| newQueenPosition.rightDiagonal === currentQueenPosition.rightDiagonal
)
) {
// Can't place queen into current position since there are other queens that
Expand Down
2 changes: 1 addition & 1 deletion src/data-structures/doubly-linked-list/DoublyLinkedList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DoublyLinkedListNode from './DoublyLinkedListNode';
import Comparator from './../../utils/comparator/Comparator';
import Comparator from '../../utils/comparator/Comparator';

export default class DoublyLinkedList {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DoublyLinkedListNode from './../DoublyLinkedListNode';
import DoublyLinkedListNode from '../DoublyLinkedListNode';

describe('DoublyLinkedListNode', () => {
it('should create list node with value', () => {
Expand Down
16 changes: 8 additions & 8 deletions src/data-structures/heap/MinHeap.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ export default class MinHeap {
// If there is no parent or parent is less then node to delete then heapify down.
// Otherwise heapify up.
if (
leftChild !== null &&
(
parentItem === null ||
this.compare.lessThan(parentItem, this.heapContainer[indexToRemove])
leftChild !== null
&& (
parentItem === null
|| this.compare.lessThan(parentItem, this.heapContainer[indexToRemove])
)
) {
this.heapifyDown(indexToRemove);
Expand Down Expand Up @@ -208,8 +208,8 @@ export default class MinHeap {
let currentIndex = customStartIndex || this.heapContainer.length - 1;

while (
this.hasParent(currentIndex) &&
this.compare.lessThan(this.heapContainer[currentIndex], this.parent(currentIndex))
this.hasParent(currentIndex)
&& this.compare.lessThan(this.heapContainer[currentIndex], this.parent(currentIndex))
) {
this.swap(currentIndex, this.getParentIndex(currentIndex));
currentIndex = this.getParentIndex(currentIndex);
Expand All @@ -227,8 +227,8 @@ export default class MinHeap {

while (this.hasLeftChild(currentIndex)) {
if (
this.hasRightChild(currentIndex) &&
this.compare.lessThan(this.rightChild(currentIndex), this.leftChild(currentIndex))
this.hasRightChild(currentIndex)
&& this.compare.lessThan(this.rightChild(currentIndex), this.leftChild(currentIndex))
) {
nextIndex = this.getRightChildIndex(currentIndex);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
this.setLeft(newNode);

return newNode;
} else if (this.nodeValueComparator.greaterThan(value, this.value)) {
}

if (this.nodeValueComparator.greaterThan(value, this.value)) {
// Insert to the right.
if (this.right) {
return this.right.insert(value);
Expand Down Expand Up @@ -63,7 +65,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
if (this.nodeValueComparator.lessThan(value, this.value) && this.left) {
// Check left nodes.
return this.left.find(value);
} else if (this.nodeValueComparator.greaterThan(value, this.value) && this.right) {
}

if (this.nodeValueComparator.greaterThan(value, this.value) && this.right) {
// Check right nodes.
return this.right.find(value);
}
Expand Down

0 comments on commit 17ad4dc

Please sign in to comment.