Skip to content

Commit c55ca93

Browse files
committed
Updated the count sort algorithm with stable implementation. Added ES6 syntactic sugar to the syntax
1 parent 376f60d commit c55ca93

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

Sorts/CountingSort.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ const countingSort = (arr, min, max) => {
1212
// Create an auxiliary resultant array
1313
const res = []
1414
// Create the freq array
15-
const count = []
1615
let len = max - min + 1
17-
18-
for (let i = 0; i < len; i++) {
19-
count[i] = 0
20-
}
16+
const count = new Array(len).fill(0)
2117
// Populate the freq array
2218
for (let i = 0; i < arr.length; i++) {
2319
count[arr[i] - min] += 1

0 commit comments

Comments
 (0)