mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00
Updated the count sort algorithm with stable implementation. Added ES6 syntactic sugar to the syntax
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user