var arr var counts for var arr length counts arra var sorted for var c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
var arr = [5, 4, 2, 1, 1, 2, 3]
var counts = [0, 0, 0, 0, 0, 0, 0];
for (var i = 0; i < arr.length; i++) {
counts[arra[i]]++;
}
var sorted = [];
for (var i = 0; i < counts.length; i++) {
for (var j = 0; j < counts[i]; j++) {
sorted.push(i);
}
}