Skip to content

Commit 8ccee06

Browse files
Merge pull request akshitagit#180 from bilalzhd/patch-2
Update countSort.js
2 parents 387655c + 8c2e649 commit 8ccee06

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Algorithms/countSort.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ let countingSort = (arr) => {
33
j = 0,
44
len = arr.length,
55
count = [];
6-
let max = Math.min;
7-
for(let i = 0; i<arr.length; i++){
8-
if(arr[i] > max) max = arr[i];
9-
}
10-
for (i; i <= max; i++) {
6+
let max = Math.max(...arr);
7+
for (i; i <= max; i++) {
118
count[i] = 0;
12-
}
13-
for (i = 0; i < len; i++) {
9+
}
10+
for (i = 0; i < len; i++) {
1411
count[arr[i]] += 1;
15-
}
16-
for (i = 0; i <= max; i++) {
12+
}
13+
for (i = 0; i <= max; i++) {
1714
while (count[i] > 0) {
1815
arr[j] = i;
1916
j++;

0 commit comments

Comments
 (0)