From 6bd6072d45cc31b12c7b24effa305c94e9fd8472 Mon Sep 17 00:00:00 2001 From: Yavorski Date: Wed, 17 Oct 2018 06:19:14 +0300 Subject: [PATCH] Properly detect min and max element in array (#224) --- .../sorting/counting-sort/__test__/CountingSort.test.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/algorithms/sorting/counting-sort/__test__/CountingSort.test.js b/src/algorithms/sorting/counting-sort/__test__/CountingSort.test.js index be15d032..9bf5d5c5 100644 --- a/src/algorithms/sorting/counting-sort/__test__/CountingSort.test.js +++ b/src/algorithms/sorting/counting-sort/__test__/CountingSort.test.js @@ -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);