mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 07:01: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 });
|
||||
|
||||
// Detect biggest number in array in prior.
|
||||
const biggestElement = notSortedArr.reduce((accumulator, element) => {
|
||||
return element > accumulator ? element : accumulator;
|
||||
}, 0);
|
||||
const biggestElement = Math.max(...notSortedArr);
|
||||
|
||||
// Detect smallest number in array in prior.
|
||||
const smallestElement = notSortedArr.reduce((accumulator, element) => {
|
||||
return element < accumulator ? element : accumulator;
|
||||
}, 0);
|
||||
const smallestElement = Math.min(...notSortedArr);
|
||||
|
||||
const sortedArray = sorter.sort(notSortedArr, smallestElement, biggestElement);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user