JSFiddle - React, Tailwind, and code Playground
by isqua
JavaScript
var a = [1, 2, 1, 4, 1, 5, 24, 2, 5, 3, 4, 25, 21, 50, 101, 21, 3];
var hash = [];
var result = [];
a.forEach(function(n) {
hash[n] = hash[n] || 0;
hash[n]++;
});
hash.forEach(function(i, n) {
var j;
if (i) {
for (j = 0; j < i; j++) {
result.push(n);
}
}
});
console.log(result);