mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 23:21:18 +08:00
Properly detect min and max element in array (#224)
This commit is contained in:
parent
5d12638ab5
commit
6bd6072d45
@ -27,14 +27,10 @@ describe('CountingSort', () => {
|
|||||||
const sorter = new CountingSort({ visitingCallback });
|
const sorter = new CountingSort({ visitingCallback });
|
||||||
|
|
||||||
// Detect biggest number in array in prior.
|
// Detect biggest number in array in prior.
|
||||||
const biggestElement = notSortedArr.reduce((accumulator, element) => {
|
const biggestElement = Math.max(...notSortedArr);
|
||||||
return element > accumulator ? element : accumulator;
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
// Detect smallest number in array in prior.
|
// Detect smallest number in array in prior.
|
||||||
const smallestElement = notSortedArr.reduce((accumulator, element) => {
|
const smallestElement = Math.min(...notSortedArr);
|
||||||
return element < accumulator ? element : accumulator;
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
const sortedArray = sorter.sort(notSortedArr, smallestElement, biggestElement);
|
const sortedArray = sorter.sort(notSortedArr, smallestElement, biggestElement);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user