Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6bd6072

Browse files
Yavorskitrekhleb
Yavorski
authored andcommitted
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‎

Lines changed: 2 additions & 6 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /