Skip to content

Commit 6bd6072

Browse files
Yavorskitrekhleb
Yavorski
authored andcommittedOct 17, 2018
Properly detect min and max element in array (trekhleb#224)
1 parent 5d12638 commit 6bd6072

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed
 

‎src/algorithms/sorting/counting-sort/__test__/CountingSort.test.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ describe('CountingSort', () => {
2727
const sorter = new CountingSort({ visitingCallback });
2828

2929
// Detect biggest number in array in prior.
30-
const biggestElement = notSortedArr.reduce((accumulator, element) => {
31-
return element > accumulator ? element : accumulator;
32-
}, 0);
30+
const biggestElement = Math.max(...notSortedArr);
3331

3432
// Detect smallest number in array in prior.
35-
const smallestElement = notSortedArr.reduce((accumulator, element) => {
36-
return element < accumulator ? element : accumulator;
37-
}, 0);
33+
const smallestElement = Math.min(...notSortedArr);
3834

3935
const sortedArray = sorter.sort(notSortedArr, smallestElement, biggestElement);
4036

0 commit comments

Comments
 (0)
Please sign in to comment.