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

2137
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", "homepage": "https://github.com/trekhleb/javascript-algorithms#readme",
"devDependencies": { "devDependencies": {
"@types/jest": "^22.2.3", "@types/jest": "^23.1.4",
"babel-cli": "^6.26.0", "babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0", "babel-preset-env": "^1.7.0",
"codecov": "^3.0.2", "codecov": "^3.0.2",
"eslint": "^4.19.1", "eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0", "eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.12.0", "eslint-plugin-import": "^2.13.0",
"eslint-plugin-jest": "^21.15.2", "eslint-plugin-jest": "^21.17.0",
"eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-jsx-a11y": "^6.1.0",
"eslint-plugin-react": "^7.8.2", "eslint-plugin-react": "^7.10.0",
"jest": "^22.4.4", "jest": "^23.3.0",
"pre-commit": "^1.2.2" "pre-commit": "^1.2.2"
}, },
"dependencies": {} "dependencies": {}

View File

@ -60,8 +60,8 @@ export default function prim(graph) {
nextMinVertex.getEdges().forEach((graphEdge) => { nextMinVertex.getEdges().forEach((graphEdge) => {
// Add only vertices that link to unvisited nodes. // Add only vertices that link to unvisited nodes.
if ( if (
!visitedVertices[graphEdge.startVertex.getKey()] || !visitedVertices[graphEdge.startVertex.getKey()]
!visitedVertices[graphEdge.endVertex.getKey()] || !visitedVertices[graphEdge.endVertex.getKey()]
) { ) {
edgesQueue.add(graphEdge, graphEdge.weight); edgesQueue.add(graphEdge, graphEdge.weight);
} }

View File

@ -11,7 +11,9 @@ export default function trialDivision(number) {
if (number <= 1) { if (number <= 1) {
// If number is less than one then it isn't prime by definition. // If number is less than one then it isn't prime by definition.
return false; return false;
} else if (number <= 3) { }
if (number <= 3) {
// All numbers from 2 to 3 are prime. // All numbers from 2 to 3 are prime.
return true; 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 // In this case this would mean that we need to include previous item
// to the list of selected items. // to the list of selected items.
if ( if (
knapsackMatrix[itemIndex][weightIndex] && knapsackMatrix[itemIndex][weightIndex]
knapsackMatrix[itemIndex][weightIndex] === knapsackMatrix[itemIndex - 1][weightIndex] && knapsackMatrix[itemIndex][weightIndex] === knapsackMatrix[itemIndex - 1][weightIndex]
) { ) {
// Check if there are several items with the same weight but with the different values. // 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. // We need to add highest item in the matrix that is possible to get the highest value.
const prevSumValue = knapsackMatrix[itemIndex - 1][weightIndex]; const prevSumValue = knapsackMatrix[itemIndex - 1][weightIndex];
const prevPrevSumValue = knapsackMatrix[itemIndex - 2][weightIndex]; const prevPrevSumValue = knapsackMatrix[itemIndex - 2][weightIndex];
if ( if (
!prevSumValue || !prevSumValue
(prevSumValue && prevPrevSumValue !== prevSumValue) || (prevSumValue && prevPrevSumValue !== prevSumValue)
) { ) {
this.selectedItems.push(prevItem); 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. // Go and check if previous elements and greater then current one.
// If this is the case then swap that elements. // If this is the case then swap that elements.
while ( while (
array[currentIndex - 1] !== undefined && array[currentIndex - 1] !== undefined
this.comparator.lessThan(array[currentIndex], array[currentIndex - 1]) && this.comparator.lessThan(array[currentIndex], array[currentIndex - 1])
) { ) {
// Call visiting callback. // Call visiting callback.
this.callbacks.visitingCallback(array[currentIndex - 1]); this.callbacks.visitingCallback(array[currentIndex - 1]);

View File

@ -18,9 +18,9 @@ export default class RadixSort extends Sort {
const numPasses = this.determineNumPasses(sortedArray); const numPasses = this.determineNumPasses(sortedArray);
for (let currentIndex = 0; currentIndex < numPasses; currentIndex += 1) { for (let currentIndex = 0; currentIndex < numPasses; currentIndex += 1) {
const buckets = isArrayOfNumbers ? const buckets = isArrayOfNumbers
this.placeElementsInNumberBuckets(sortedArray, currentIndex) : ? this.placeElementsInNumberBuckets(sortedArray, currentIndex)
this.placeElementsInCharacterBuckets(sortedArray, currentIndex, numPasses); : this.placeElementsInCharacterBuckets(sortedArray, currentIndex, numPasses);
// Flatten buckets into sortedArray, and repeat at next index // Flatten buckets into sortedArray, and repeat at next index
sortedArray = buckets.reduce((acc, val) => { sortedArray = buckets.reduce((acc, val) => {

View File

@ -88,18 +88,18 @@ export default function regularExpressionMatching(string, pattern) {
matchMatrix[rowIndex][columnIndex] = true; matchMatrix[rowIndex][columnIndex] = true;
} else if ( } else if (
( (
pattern[patternIndex - 1] === string[stringIndex] || pattern[patternIndex - 1] === string[stringIndex]
pattern[patternIndex - 1] === ANY_CHAR || pattern[patternIndex - 1] === ANY_CHAR
) && )
matchMatrix[rowIndex - 1][columnIndex] === true && matchMatrix[rowIndex - 1][columnIndex] === true
) { ) {
matchMatrix[rowIndex][columnIndex] = true; matchMatrix[rowIndex][columnIndex] = true;
} else { } else {
matchMatrix[rowIndex][columnIndex] = false; matchMatrix[rowIndex][columnIndex] = false;
} }
} else if ( } else if (
pattern[patternIndex] === string[stringIndex] || pattern[patternIndex] === string[stringIndex]
pattern[patternIndex] === ANY_CHAR || pattern[patternIndex] === ANY_CHAR
) { ) {
/* /*
* In case if current pattern char is the same as current string 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 // more characters that are equal to the ones in the prefix we will expand
// right Z box boundary by 3. // right Z box boundary by 3.
while ( while (
zBoxRightIndex < zString.length && zBoxRightIndex < zString.length
zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex] && zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
) { ) {
// Expanding Z box right boundary. // Expanding Z box right boundary.
zBoxRightIndex += 1; zBoxRightIndex += 1;
@ -81,8 +81,8 @@ function buildZArray(zString) {
// And start comparing characters one by one as we normally do for the case // And start comparing characters one by one as we normally do for the case
// when we are outside of checkbox. // when we are outside of checkbox.
while ( while (
zBoxRightIndex < zString.length && zBoxRightIndex < zString.length
zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex] && zString[zBoxRightIndex - zBoxLeftIndex] === zString[zBoxRightIndex]
) { ) {
zBoxRightIndex += 1; zBoxRightIndex += 1;
} }

View File

@ -16,16 +16,16 @@ function isSafe(queensPositions, rowIndex, columnIndex) {
if ( if (
// Check if queen has been already placed. // Check if queen has been already placed.
currentQueenPosition && currentQueenPosition
( && (
// Check if there are any queen on the same column. // 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. // 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. // 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. // 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 // Can't place queen into current position since there are other queens that

View File

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

View File

@ -1,4 +1,4 @@
import DoublyLinkedListNode from './../DoublyLinkedListNode'; import DoublyLinkedListNode from '../DoublyLinkedListNode';
describe('DoublyLinkedListNode', () => { describe('DoublyLinkedListNode', () => {
it('should create list node with value', () => { 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. // If there is no parent or parent is less then node to delete then heapify down.
// Otherwise heapify up. // Otherwise heapify up.
if ( if (
leftChild !== null && leftChild !== null
( && (
parentItem === null || parentItem === null
this.compare.lessThan(parentItem, this.heapContainer[indexToRemove]) || this.compare.lessThan(parentItem, this.heapContainer[indexToRemove])
) )
) { ) {
this.heapifyDown(indexToRemove); this.heapifyDown(indexToRemove);
@ -208,8 +208,8 @@ export default class MinHeap {
let currentIndex = customStartIndex || this.heapContainer.length - 1; let currentIndex = customStartIndex || this.heapContainer.length - 1;
while ( while (
this.hasParent(currentIndex) && this.hasParent(currentIndex)
this.compare.lessThan(this.heapContainer[currentIndex], this.parent(currentIndex)) && this.compare.lessThan(this.heapContainer[currentIndex], this.parent(currentIndex))
) { ) {
this.swap(currentIndex, this.getParentIndex(currentIndex)); this.swap(currentIndex, this.getParentIndex(currentIndex));
currentIndex = this.getParentIndex(currentIndex); currentIndex = this.getParentIndex(currentIndex);
@ -227,8 +227,8 @@ export default class MinHeap {
while (this.hasLeftChild(currentIndex)) { while (this.hasLeftChild(currentIndex)) {
if ( if (
this.hasRightChild(currentIndex) && this.hasRightChild(currentIndex)
this.compare.lessThan(this.rightChild(currentIndex), this.leftChild(currentIndex)) && this.compare.lessThan(this.rightChild(currentIndex), this.leftChild(currentIndex))
) { ) {
nextIndex = this.getRightChildIndex(currentIndex); nextIndex = this.getRightChildIndex(currentIndex);
} else { } else {

View File

@ -35,7 +35,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
this.setLeft(newNode); this.setLeft(newNode);
return newNode; return newNode;
} else if (this.nodeValueComparator.greaterThan(value, this.value)) { }
if (this.nodeValueComparator.greaterThan(value, this.value)) {
// Insert to the right. // Insert to the right.
if (this.right) { if (this.right) {
return this.right.insert(value); return this.right.insert(value);
@ -63,7 +65,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
if (this.nodeValueComparator.lessThan(value, this.value) && this.left) { if (this.nodeValueComparator.lessThan(value, this.value) && this.left) {
// Check left nodes. // Check left nodes.
return this.left.find(value); 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. // Check right nodes.
return this.right.find(value); return this.right.find(value);
} }