Upgrade packages.

This commit is contained in:
Oleksii Trekhleb 2018-07-05 16:30:00 +03:00
parent 58640ee7b5
commit 17ad4dc4d1
14 changed files with 1695 additions and 542 deletions

2135
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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": {}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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]);

View File

@ -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) => {

View File

@ -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

View File

@ -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;
@ -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;
}

View File

@ -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

View File

@ -1,5 +1,5 @@
import DoublyLinkedListNode from './DoublyLinkedListNode';
import Comparator from './../../utils/comparator/Comparator';
import Comparator from '../../utils/comparator/Comparator';
export default class DoublyLinkedList {
/**

View File

@ -1,4 +1,4 @@
import DoublyLinkedListNode from './../DoublyLinkedListNode';
import DoublyLinkedListNode from '../DoublyLinkedListNode';
describe('DoublyLinkedListNode', () => {
it('should create list node with value', () => {

View File

@ -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);
@ -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);
@ -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 {

View File

@ -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);
@ -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);
}