Upgrade dependencies and fix ESLint issues.

This commit is contained in:
Oleksii Trekhleb
2020-07-26 13:06:15 +02:00
parent 4d8baf87db
commit 63f5a27152
36 changed files with 4442 additions and 1630 deletions

View File

@@ -16,7 +16,7 @@ export default class BloomFilter {
const hashValues = this.getHashValues(item);
// Set each hashValue index to true.
hashValues.forEach(val => this.storage.setValue(val));
hashValues.forEach((val) => this.storage.setValue(val));
}
/**

View File

@@ -51,7 +51,7 @@ describe('BloomFilter', () => {
});
it('should insert strings correctly and return true when checking for inserted values', () => {
people.forEach(person => bloomFilter.insert(person));
people.forEach((person) => bloomFilter.insert(person));
expect(bloomFilter.mayContain('Bruce Wayne')).toBe(true);
expect(bloomFilter.mayContain('Clark Kent')).toBe(true);

View File

@@ -94,7 +94,7 @@ describe('DisjointSet', () => {
});
it('should do basic manipulations on disjoint set with custom key extractor', () => {
const keyExtractor = value => value.key;
const keyExtractor = (value) => value.key;
const disjointSet = new DisjointSet(keyExtractor);

View File

@@ -218,7 +218,7 @@ export default class DoublyLinkedList {
* @return {DoublyLinkedList}
*/
fromArray(values) {
values.forEach(value => this.append(value));
values.forEach((value) => this.append(value));
return this;
}
@@ -228,7 +228,7 @@ export default class DoublyLinkedList {
* @return {string}
*/
toString(callback) {
return this.toArray().map(node => node.toString(callback)).toString();
return this.toArray().map((node) => node.toString(callback)).toString();
}
/**

View File

@@ -164,7 +164,7 @@ describe('DoublyLinkedList', () => {
.append(nodeValue1)
.prepend(nodeValue2);
const nodeStringifier = value => `${value.key}:${value.value}`;
const nodeStringifier = (value) => `${value.key}:${value.value}`;
expect(linkedList.toString(nodeStringifier)).toBe('key2:2,key1:1');
});
@@ -195,12 +195,12 @@ describe('DoublyLinkedList', () => {
.append({ value: 2, key: 'test2' })
.append({ value: 3, key: 'test3' });
const node = linkedList.find({ callback: value => value.key === 'test2' });
const node = linkedList.find({ callback: (value) => value.key === 'test2' });
expect(node).toBeDefined();
expect(node.value.value).toBe(2);
expect(node.value.key).toBe('test2');
expect(linkedList.find({ callback: value => value.key === 'test5' })).toBeNull();
expect(linkedList.find({ callback: (value) => value.key === 'test5' })).toBeNull();
});
it('should find node by means of custom compare function', () => {

View File

@@ -48,7 +48,7 @@ describe('DoublyLinkedListNode', () => {
it('should convert node to string with custom stringifier', () => {
const nodeValue = { value: 1, key: 'test' };
const node = new DoublyLinkedListNode(nodeValue);
const toStringCallback = value => `value: ${value.value}, key: ${value.key}`;
const toStringCallback = (value) => `value: ${value.value}, key: ${value.key}`;
expect(node.toString(toStringCallback)).toBe('value: 1, key: test');
});

View File

@@ -64,7 +64,7 @@ export default class GraphVertex {
* @return {GraphEdge[]}
*/
getEdges() {
return this.edges.toArray().map(linkedListNode => linkedListNode.value);
return this.edges.toArray().map((linkedListNode) => linkedListNode.value);
}
/**
@@ -80,7 +80,7 @@ export default class GraphVertex {
*/
hasEdge(requiredEdge) {
const edgeNode = this.edges.find({
callback: edge => edge === requiredEdge,
callback: (edge) => edge === requiredEdge,
});
return !!edgeNode;
@@ -92,7 +92,7 @@ export default class GraphVertex {
*/
hasNeighbor(vertex) {
const vertexNode = this.edges.find({
callback: edge => edge.startVertex === vertex || edge.endVertex === vertex,
callback: (edge) => edge.startVertex === vertex || edge.endVertex === vertex,
});
return !!vertexNode;
@@ -123,7 +123,7 @@ export default class GraphVertex {
* @return {GraphVertex}
*/
deleteAllEdges() {
this.getEdges().forEach(edge => this.deleteEdge(edge));
this.getEdges().forEach((edge) => this.deleteEdge(edge));
return this;
}

View File

@@ -52,7 +52,7 @@ export default class HashTable {
const keyHash = this.hash(key);
this.keys[key] = keyHash;
const bucketLinkedList = this.buckets[keyHash];
const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key });
const node = bucketLinkedList.find({ callback: (nodeValue) => nodeValue.key === key });
if (!node) {
// Insert new node.
@@ -71,7 +71,7 @@ export default class HashTable {
const keyHash = this.hash(key);
delete this.keys[key];
const bucketLinkedList = this.buckets[keyHash];
const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key });
const node = bucketLinkedList.find({ callback: (nodeValue) => nodeValue.key === key });
if (node) {
return bucketLinkedList.delete(node.value);
@@ -86,7 +86,7 @@ export default class HashTable {
*/
get(key) {
const bucketLinkedList = this.buckets[this.hash(key)];
const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key });
const node = bucketLinkedList.find({ callback: (nodeValue) => nodeValue.key === key });
return node ? node.value.value : undefined;
}

View File

@@ -35,7 +35,7 @@ describe('HashTable', () => {
expect(hashTable.has('b')).toBe(true);
expect(hashTable.has('c')).toBe(true);
const stringifier = value => `${value.key}:${value.value}`;
const stringifier = (value) => `${value.key}:${value.value}`;
expect(hashTable.buckets[0].toString(stringifier)).toBe('c:earth');
expect(hashTable.buckets[1].toString(stringifier)).toBe('a:sky,d:ocean');

View File

@@ -180,7 +180,7 @@ export default class LinkedList {
* @return {LinkedList}
*/
fromArray(values) {
values.forEach(value => this.append(value));
values.forEach((value) => this.append(value));
return this;
}
@@ -205,7 +205,7 @@ export default class LinkedList {
* @return {string}
*/
toString(callback) {
return this.toArray().map(node => node.toString(callback)).toString();
return this.toArray().map((node) => node.toString(callback)).toString();
}
/**

View File

@@ -146,7 +146,7 @@ describe('LinkedList', () => {
.append(nodeValue1)
.prepend(nodeValue2);
const nodeStringifier = value => `${value.key}:${value.value}`;
const nodeStringifier = (value) => `${value.key}:${value.value}`;
expect(linkedList.toString(nodeStringifier)).toBe('key2:2,key1:1');
});
@@ -177,12 +177,12 @@ describe('LinkedList', () => {
.append({ value: 2, key: 'test2' })
.append({ value: 3, key: 'test3' });
const node = linkedList.find({ callback: value => value.key === 'test2' });
const node = linkedList.find({ callback: (value) => value.key === 'test2' });
expect(node).toBeDefined();
expect(node.value.value).toBe(2);
expect(node.value.key).toBe('test2');
expect(linkedList.find({ callback: value => value.key === 'test5' })).toBeNull();
expect(linkedList.find({ callback: (value) => value.key === 'test5' })).toBeNull();
});
it('should create linked list from array', () => {

View File

@@ -39,7 +39,7 @@ describe('LinkedListNode', () => {
it('should convert node to string with custom stringifier', () => {
const nodeValue = { value: 1, key: 'test' };
const node = new LinkedListNode(nodeValue);
const toStringCallback = value => `value: ${value.value}, key: ${value.key}`;
const toStringCallback = (value) => `value: ${value.value}, key: ${value.key}`;
expect(node.toString(toStringCallback)).toBe('value: 1, key: test');
});

View File

@@ -22,7 +22,7 @@ describe('Queue', () => {
queue.enqueue({ value: 'test1', key: 'key1' });
queue.enqueue({ value: 'test2', key: 'key2' });
const stringifier = value => `${value.key}:${value.value}`;
const stringifier = (value) => `${value.key}:${value.value}`;
expect(queue.toString(stringifier)).toBe('key1:test1,key2:test2');
expect(queue.dequeue().value).toBe('test1');

View File

@@ -54,7 +54,7 @@ export default class Stack {
toArray() {
return this.linkedList
.toArray()
.map(linkedListNode => linkedListNode.value);
.map((linkedListNode) => linkedListNode.value);
}
/**

View File

@@ -56,7 +56,7 @@ describe('Stack', () => {
stack.push({ value: 'test1', key: 'key1' });
stack.push({ value: 'test2', key: 'key2' });
const stringifier = value => `${value.key}:${value.value}`;
const stringifier = (value) => `${value.key}:${value.value}`;
expect(stack.toString(stringifier)).toBe('key2:test2,key1:test1');
expect(stack.pop().value).toBe('test2');