Skip to content

Commit 650e309

Browse files
committed
Merge branches 'issue-102-rabin-karp-fix' and 'master' of https://github.com/trekhleb/javascript-algorithms into issue-102-rabin-karp-fix
2 parents c4605ea + 7c9601d commit 650e309

File tree

21 files changed

+64
-29
lines changed

21 files changed

+64
-29
lines changed

README.ko-KR.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ _Read this in other languages:_
4848

4949
## 알고리즘
5050

51-
알고리즘은 어떤 종료의 문제를 풀 수 있는 정확한 방법이며,
51+
알고리즘은 어떤 종류의 문제를 풀 수 있는 정확한 방법이며,
5252
일련의 작업을 정확하게 정의해 놓은 규칙들입니다.
5353

5454
`B` - 입문자, `A` - 숙련자

src/algorithms/graph/kruskal/kruskal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function kruskal(graph) {
1010
// It should fire error if graph is directed since the algorithm works only
1111
// for undirected graphs.
1212
if (graph.isDirected) {
13-
throw new Error('Prim\'s algorithms works only for undirected graphs');
13+
throw new Error('Kruskal\'s algorithms works only for undirected graphs');
1414
}
1515

1616
// Init new graph that will contain minimum spanning tree of original graph.

src/algorithms/sets/combination-sum/combinationSum.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ function combinationSumRecursive(
1515
) {
1616
if (remainingSum < 0) {
1717
// By adding another candidate we've gone below zero.
18-
// This would mean that last candidate was not acceptable.
18+
// This would mean that the last candidate was not acceptable.
1919
return finalCombinations;
2020
}
2121

2222
if (remainingSum === 0) {
23-
// In case if after adding the previous candidate out remaining sum
24-
// became zero we need to same current combination since it is one
25-
// of the answer we're looking for.
23+
// If after adding the previous candidate our remaining sum
24+
// became zero - we need to save the current combination since it is one
25+
// of the answers we're looking for.
2626
finalCombinations.push(currentCombination.slice());
2727

2828
return finalCombinations;
2929
}
3030

31-
// In case if we haven't reached zero yet let's continue to add all
31+
// If we haven't reached zero yet let's continue to add all
3232
// possible candidates that are left.
3333
for (let candidateIndex = startFrom; candidateIndex < candidates.length; candidateIndex += 1) {
3434
const currentCandidate = candidates[candidateIndex];

src/data-structures/bloom-filter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Bloom Filter
22

3-
A bloom filter is a space-efficient probabilistic
3+
A **bloom filter** is a space-efficient probabilistic
44
data structure designed to test whether an element
55
is present in a set. It is designed to be blazingly
66
fast and use minimal memory at the cost of potential

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ export default class DoublyLinkedList {
213213
return nodes;
214214
}
215215

216+
/**
217+
* @param {*[]} values - Array of values that need to be converted to linked list.
218+
* @return {DoublyLinkedList}
219+
*/
220+
fromArray(values) {
221+
values.forEach(value => this.append(value));
222+
223+
return this;
224+
}
225+
216226
/**
217227
* @param {function} [callback]
218228
* @return {string}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ describe('DoublyLinkedList', () => {
3636
expect(linkedList.toString()).toBe('3,2,1');
3737
});
3838

39+
it('should create linked list from array', () => {
40+
const linkedList = new DoublyLinkedList();
41+
linkedList.fromArray([1, 1, 2, 3, 3, 3, 4, 5]);
42+
43+
expect(linkedList.toString()).toBe('1,1,2,3,3,3,4,5');
44+
});
45+
3946
it('should delete node by value from linked list', () => {
4047
const linkedList = new DoublyLinkedList();
4148

src/data-structures/graph/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Graph
22

3-
In computer science, a graph is an abstract data type
3+
In computer science, a **graph** is an abstract data type
44
that is meant to implement the undirected graph and
55
directed graph concepts from mathematics, specifically
66
the field of graph theory

src/data-structures/hash-table/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Hash Table
22

3-
In computing, a hash table (hash map) is a data
4-
structure which implements an associative array
5-
abstract data type, a structure that can map keys
6-
to values. A hash table uses a hash function to
3+
In computing, a **hash table** (hash map) is a data
4+
structure which implements an *associative array*
5+
abstract data type, a structure that can *map keys
6+
to values*. A hash table uses a *hash function* to
77
compute an index into an array of buckets or slots,
88
from which the desired value can be found
99

src/data-structures/heap/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Heap (data-structure)
22

3-
In computer science, a heap is a specialized tree-based
3+
In computer science, a **heap** is a specialized tree-based
44
data structure that satisfies the heap property described
55
below.
66

src/data-structures/linked-list/LinkedList.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export default class LinkedList {
6565

6666
let deletedNode = null;
6767

68-
// If the head must be deleted then make 2nd node to be a head.
68+
// If the head must be deleted then make next node that is differ
69+
// from the head to be a new head.
6970
while (this.head && this.compare.equal(this.head.value, value)) {
7071
deletedNode = this.head;
7172
this.head = this.head.next;
@@ -127,17 +128,17 @@ export default class LinkedList {
127128
* @return {LinkedListNode}
128129
*/
129130
deleteTail() {
131+
const deletedTail = this.tail;
132+
130133
if (this.head === this.tail) {
131134
// There is only one node in linked list.
132-
const deletedTail = this.tail;
133135
this.head = null;
134136
this.tail = null;
135137

136138
return deletedTail;
137139
}
138140

139141
// If there are many nodes in linked list...
140-
const deletedTail = this.tail;
141142

142143
// Rewind to the last node and delete "next" link for the node before the last one.
143144
let currentNode = this.head;
@@ -174,6 +175,16 @@ export default class LinkedList {
174175
return deletedHead;
175176
}
176177

178+
/**
179+
* @param {*[]} values - Array of values that need to be converted to linked list.
180+
* @return {LinkedList}
181+
*/
182+
fromArray(values) {
183+
values.forEach(value => this.append(value));
184+
185+
return this;
186+
}
187+
177188
/**
178189
* @return {LinkedListNode[]}
179190
*/

0 commit comments

Comments
 (0)