From 182f89b2c4435e614bd9e208c153b4a06efccc03 Mon Sep 17 00:00:00 2001 From: aestheticw3 <48285878+aestheticw3@users.noreply.github.com> Date: Wed, 9 Aug 2023 06:09:34 +0700 Subject: [PATCH] square brackets fix (#263) --- .../javascript/quick_sort/05_quicksort.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/04_quicksort/javascript/quick_sort/05_quicksort.js b/04_quicksort/javascript/quick_sort/05_quicksort.js index 6a8f6a6..483baf3 100644 --- a/04_quicksort/javascript/quick_sort/05_quicksort.js +++ b/04_quicksort/javascript/quick_sort/05_quicksort.js @@ -6,19 +6,19 @@ * @returns {Array} Sorted array */ function quicksort(array) { - // base case, arrays with 0 or 1 element are already "sorted" - if (array.length < 2) return array; - // recursive case - let pivot = array[0]; - // sub-array of all the elements less than the pivot - let less = array.slice(1).filter(function(el) { - return el <= pivot; - }); - // sub-array of all the elements greater than the pivot - let greater = array.slice(1).filter(function(el) { - return el > pivot; - }); - return quicksort(less).concat([pivot], quicksort(greater)); + // base case, arrays with 0 or 1 element are already "sorted" + if (array.length < 2) return array; + // recursive case + let pivot = array[0]; + // sub-array of all the elements less than the pivot + let less = array.slice(1).filter(function (el) { + return el <= pivot; + }); + // sub-array of all the elements greater than the pivot + let greater = array.slice(1).filter(function (el) { + return el > pivot; + }); + return quicksort(less).concat(pivot, quicksort(greater)); } -console.log(quicksort([10, 5, 2, 3])); +console.log(quicksort([10, 5, 2, 3]));