From c55ca93584e7e00b34c8ee3c4d5ebab76a6acec5 Mon Sep 17 00:00:00 2001 From: Mandy8055 Date: Sun, 8 Aug 2021 16:42:13 +0530 Subject: [PATCH] Updated the count sort algorithm with stable implementation. Added ES6 syntactic sugar to the syntax --- Sorts/CountingSort.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Sorts/CountingSort.js b/Sorts/CountingSort.js index 01bfc2b7e..cc2dd18e5 100644 --- a/Sorts/CountingSort.js +++ b/Sorts/CountingSort.js @@ -12,12 +12,8 @@ const countingSort = (arr, min, max) => { // Create an auxiliary resultant array const res = [] // Create the freq array - const count = [] let len = max - min + 1 - - for (let i = 0; i < len; i++) { - count[i] = 0 - } + const count = new Array(len).fill(0) // Populate the freq array for (let i = 0; i < arr.length; i++) { count[arr[i] - min] += 1