function foo(arr){
var dict = {};
var result = [];
for(var i = 0, len = arr.length; i < len; ++i){
if(arr[i] in dict){
++dict[arr[i]];
}else{
dict[arr[i]] = 1;
}
}
var sortedKeys = Object.keys(dict).sort();
for(i = 0, len = sortedKeys.length; i < len; ++i){
var tmpArr = []
for(var j = 0, jLen=dict[sortedKeys[i]]; j < jLen; ++j){
tmpArr.push(sortedKeys[i]);
}
result.push(tmpArr);
}
return result;
}
或者使用简单的方式来实现: