Updated the count sort algorithm with stable implementation. Added ES6 syntactic sugar to the syntax

This commit is contained in:
Mandy8055
2021-08-08 16:42:13 +05:30
parent 376f60ddc6
commit c55ca93584

View File

@ -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