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