BorisBritva,
var arr = [5,5,5,3,3,3,3,3,2,2,2,2,1,1,1,1,1], map = {}, result = [];;
arr.forEach(function (a) {
map[a] ? map[a]++ : map[a] = 1
});
result = Object.keys(map);
result.sort(function (a, b) {
return map[a] - map[b] || a - b
});
alert(result)