Skip to content

Commit

Permalink
Properly detect min and max element in array (trekhleb#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yavorski authored and trekhleb committed Oct 17, 2018
1 parent 5d12638 commit 6bd6072
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6bd6072

Please sign in to comment.