Properly detect min and max element in array (#224)

This commit is contained in:
Yavorski 2018-10-17 06:19:14 +03:00 committed by Oleksii Trekhleb
parent 5d12638ab5
commit 6bd6072d45

View File

@ -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);