GeezerVison is showing github.com — Fix then > than typo. · BrandonWeb/javascript-algorithms@d596e1d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/algorithms/search/binary-search/binarySearch.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,7 @@ export default function binarySearch(sortedArray, seekElement, comparatorCallbac | 22 | 22 | } | 23 | 23 |
| 24 | 24 | // Decide which half to choose for seeking next: left or right one. | 25 | | - if (comparator.lessThen(sortedArray[middleIndex], seekElement)) { | | 25 | + if (comparator.lessThan(sortedArray[middleIndex], seekElement)) { | 26 | 26 | // Go to the right half of the array. | 27 | 27 | startIndex = middleIndex + 1; | 28 | 28 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/bubble-sort/BubbleSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ export default class BubbleSort extends Sort { | 18 | 18 | this.callbacks.visitingCallback(array[j]); | 19 | 19 |
| 20 | 20 | // Swap elements if they are in wrong order. | 21 | | - if (this.comparator.lessThen(array[j + 1], array[j])) { | | 21 | + if (this.comparator.lessThan(array[j + 1], array[j])) { | 22 | 22 | const tmp = array[j + 1]; | 23 | 23 | array[j + 1] = array[j]; | 24 | 24 | array[j] = tmp; | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/insertion-sort/InsertionSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ export default class InsertionSort extends Sort { | 15 | 15 | // If this is the case then swap that elements. | 16 | 16 | while ( | 17 | 17 | array[currentIndex - 1] && | 18 | | - this.comparator.lessThen(array[currentIndex], array[currentIndex - 1]) | | 18 | + this.comparator.lessThan(array[currentIndex], array[currentIndex - 1]) | 19 | 19 | ) { | 20 | 20 | // Call visiting callback. | 21 | 21 | this.callbacks.visitingCallback(array[currentIndex - 1]); | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/merge-sort/MergeSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,7 @@ export default class MergeSort extends Sort { | 31 | 31 | let minimumElement = null; | 32 | 32 |
| 33 | 33 | // Find minimum element of two arrays. | 34 | | - if (this.comparator.lessThenOrEqual(leftArray[0], rightArray[0])) { | | 34 | + if (this.comparator.lessThanOrEqual(leftArray[0], rightArray[0])) { | 35 | 35 | minimumElement = leftArray.shift(); | 36 | 36 | } else { | 37 | 37 | minimumElement = rightArray.shift(); | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/quick-sort/QuickSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,7 @@ export default class QuickSort extends Sort { | 27 | 27 |
| 28 | 28 | if (this.comparator.equal(currentElement, pivotElement)) { | 29 | 29 | centerArray.push(currentElement); | 30 | | - } else if (this.comparator.lessThen(currentElement, pivotElement)) { | | 30 | + } else if (this.comparator.lessThan(currentElement, pivotElement)) { | 31 | 31 | leftArray.push(currentElement); | 32 | 32 | } else { | 33 | 33 | rightArray.push(currentElement); | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/selection-sort/SelectionSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,7 @@ export default class SelectionSort extends Sort { | 16 | 16 | // Call visiting callback. | 17 | 17 | this.callbacks.visitingCallback(array[j]); | 18 | 18 |
| 19 | | - if (this.comparator.lessThen(array[j], array[minIndex])) { | | 19 | + if (this.comparator.lessThan(array[j], array[minIndex])) { | 20 | 20 | minIndex = j; | 21 | 21 | } | 22 | 22 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/shell-sort/ShellSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,7 @@ export default class ShellSort extends Sort { | 20 | 20 | this.callbacks.visitingCallback(array[currentIndex]); | 21 | 21 |
| 22 | 22 | // Compare and swap array elements if needed. | 23 | | - if (this.comparator.lessThen(array[gapShiftedIndex], array[currentIndex])) { | | 23 | + if (this.comparator.lessThan(array[gapShiftedIndex], array[currentIndex])) { | 24 | 24 | const tmp = array[currentIndex]; | 25 | 25 | array[currentIndex] = array[gapShiftedIndex]; | 26 | 26 | array[gapShiftedIndex] = tmp; | |
Collapse file Copy file name to clipboardExpand all lines: src/data-structures/heap/MinHeap.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -167,7 +167,7 @@ export default class MinHeap { | 167 | 167 | leftChild !== null && | 168 | 168 | ( | 169 | 169 | parentItem === null || | 170 | | - this.compare.lessThen(parentItem, this.heapContainer[indexToRemove]) | | 170 | + this.compare.lessThan(parentItem, this.heapContainer[indexToRemove]) | 171 | 171 | ) | 172 | 172 | ) { | 173 | 173 | this.heapifyDown(indexToRemove); | @@ -209,7 +209,7 @@ export default class MinHeap { | 209 | 209 |
| 210 | 210 | while ( | 211 | 211 | this.hasParent(currentIndex) && | 212 | | - this.compare.lessThen(this.heapContainer[currentIndex], this.parent(currentIndex)) | | 212 | + this.compare.lessThan(this.heapContainer[currentIndex], this.parent(currentIndex)) | 213 | 213 | ) { | 214 | 214 | this.swap(currentIndex, this.getParentIndex(currentIndex)); | 215 | 215 | currentIndex = this.getParentIndex(currentIndex); | @@ -228,14 +228,14 @@ export default class MinHeap { | 228 | 228 | while (this.hasLeftChild(currentIndex)) { | 229 | 229 | if ( | 230 | 230 | this.hasRightChild(currentIndex) && | 231 | | - this.compare.lessThen(this.rightChild(currentIndex), this.leftChild(currentIndex)) | | 231 | + this.compare.lessThan(this.rightChild(currentIndex), this.leftChild(currentIndex)) | 232 | 232 | ) { | 233 | 233 | nextIndex = this.getRightChildIndex(currentIndex); | 234 | 234 | } else { | 235 | 235 | nextIndex = this.getLeftChildIndex(currentIndex); | 236 | 236 | } | 237 | 237 |
| 238 | | - if (this.compare.lessThen(this.heapContainer[currentIndex], this.heapContainer[nextIndex])) { | | 238 | + if (this.compare.lessThan(this.heapContainer[currentIndex], this.heapContainer[nextIndex])) { | 239 | 239 | break; | 240 | 240 | } | 241 | 241 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/utils/comparator/Comparator.js +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,20 +23,20 @@ export default class Comparator { | 23 | 23 | return this.compare(a, b) === 0; | 24 | 24 | } | 25 | 25 |
| 26 | | - lessThen(a, b) { | | 26 | + lessThan(a, b) { | 27 | 27 | return this.compare(a, b) < 0; | 28 | 28 | } | 29 | 29 |
| 30 | | - greaterThen(a, b) { | | 30 | + greaterThan(a, b) { | 31 | 31 | return this.compare(a, b) > 0; | 32 | 32 | } | 33 | 33 |
| 34 | | - lessThenOrEqual(a, b) { | 35 | | - return this.lessThen(a, b) || this.equal(a, b); | | 34 | + lessThanOrEqual(a, b) { | | 35 | + return this.lessThan(a, b) || this.equal(a, b); | 36 | 36 | } | 37 | 37 |
| 38 | | - greaterThenOrEqual(a, b) { | 39 | | - return this.greaterThen(a, b) || this.equal(a, b); | | 38 | + greaterThanOrEqual(a, b) { | | 39 | + return this.greaterThan(a, b) || this.equal(a, b); | 40 | 40 | } | 41 | 41 |
| 42 | 42 | reverse() { | |
Collapse file Copy file name to clipboardExpand all lines: src/utils/comparator/__test__/Comparator.test.js +21-21Lines changed: 21 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,19 +7,19 @@ describe('Comparator', () => { | 7 | 7 | expect(comparator.equal(0, 0)).toBeTruthy(); | 8 | 8 | expect(comparator.equal(0, 1)).toBeFalsy(); | 9 | 9 | expect(comparator.equal('a', 'a')).toBeTruthy(); | 10 | | - expect(comparator.lessThen(1, 2)).toBeTruthy(); | 11 | | - expect(comparator.lessThen(-1, 2)).toBeTruthy(); | 12 | | - expect(comparator.lessThen('a', 'b')).toBeTruthy(); | 13 | | - expect(comparator.lessThen('a', 'ab')).toBeTruthy(); | 14 | | - expect(comparator.lessThen(10, 2)).toBeFalsy(); | 15 | | - expect(comparator.lessThenOrEqual(10, 2)).toBeFalsy(); | 16 | | - expect(comparator.lessThenOrEqual(1, 1)).toBeTruthy(); | 17 | | - expect(comparator.lessThenOrEqual(0, 0)).toBeTruthy(); | 18 | | - expect(comparator.greaterThen(0, 0)).toBeFalsy(); | 19 | | - expect(comparator.greaterThen(10, 0)).toBeTruthy(); | 20 | | - expect(comparator.greaterThenOrEqual(10, 0)).toBeTruthy(); | 21 | | - expect(comparator.greaterThenOrEqual(10, 10)).toBeTruthy(); | 22 | | - expect(comparator.greaterThenOrEqual(0, 10)).toBeFalsy(); | | 10 | + expect(comparator.lessThan(1, 2)).toBeTruthy(); | | 11 | + expect(comparator.lessThan(-1, 2)).toBeTruthy(); | | 12 | + expect(comparator.lessThan('a', 'b')).toBeTruthy(); | | 13 | + expect(comparator.lessThan('a', 'ab')).toBeTruthy(); | | 14 | + expect(comparator.lessThan(10, 2)).toBeFalsy(); | | 15 | + expect(comparator.lessThanOrEqual(10, 2)).toBeFalsy(); | | 16 | + expect(comparator.lessThanOrEqual(1, 1)).toBeTruthy(); | | 17 | + expect(comparator.lessThanOrEqual(0, 0)).toBeTruthy(); | | 18 | + expect(comparator.greaterThan(0, 0)).toBeFalsy(); | | 19 | + expect(comparator.greaterThan(10, 0)).toBeTruthy(); | | 20 | + expect(comparator.greaterThanOrEqual(10, 0)).toBeTruthy(); | | 21 | + expect(comparator.greaterThanOrEqual(10, 10)).toBeTruthy(); | | 22 | + expect(comparator.greaterThanOrEqual(0, 10)).toBeFalsy(); | 23 | 23 | }); | 24 | 24 |
| 25 | 25 | it('should compare with custom comparator function', () => { | @@ -33,18 +33,18 @@ describe('Comparator', () => { | 33 | 33 |
| 34 | 34 | expect(comparator.equal('a', 'b')).toBeTruthy(); | 35 | 35 | expect(comparator.equal('a', '')).toBeFalsy(); | 36 | | - expect(comparator.lessThen('b', 'aa')).toBeTruthy(); | 37 | | - expect(comparator.greaterThenOrEqual('a', 'aa')).toBeFalsy(); | 38 | | - expect(comparator.greaterThenOrEqual('aa', 'a')).toBeTruthy(); | 39 | | - expect(comparator.greaterThenOrEqual('a', 'a')).toBeTruthy(); | | 36 | + expect(comparator.lessThan('b', 'aa')).toBeTruthy(); | | 37 | + expect(comparator.greaterThanOrEqual('a', 'aa')).toBeFalsy(); | | 38 | + expect(comparator.greaterThanOrEqual('aa', 'a')).toBeTruthy(); | | 39 | + expect(comparator.greaterThanOrEqual('a', 'a')).toBeTruthy(); | 40 | 40 |
| 41 | 41 | comparator.reverse(); | 42 | 42 |
| 43 | 43 | expect(comparator.equal('a', 'b')).toBeTruthy(); | 44 | 44 | expect(comparator.equal('a', '')).toBeFalsy(); | 45 | | - expect(comparator.lessThen('b', 'aa')).toBeFalsy(); | 46 | | - expect(comparator.greaterThenOrEqual('a', 'aa')).toBeTruthy(); | 47 | | - expect(comparator.greaterThenOrEqual('aa', 'a')).toBeFalsy(); | 48 | | - expect(comparator.greaterThenOrEqual('a', 'a')).toBeTruthy(); | | 45 | + expect(comparator.lessThan('b', 'aa')).toBeFalsy(); | | 46 | + expect(comparator.greaterThanOrEqual('a', 'aa')).toBeTruthy(); | | 47 | + expect(comparator.greaterThanOrEqual('aa', 'a')).toBeFalsy(); | | 48 | + expect(comparator.greaterThanOrEqual('a', 'a')).toBeTruthy(); | 49 | 49 | }); | 50 | 50 | }); |
|