字符串数组排序
var arr = ['chifan', '抽yan', 'he酒', '烫头', 'Coding2233'];
/**
* 计算字符串字节数
*/
function getBytesCount(str) {
var bytesCount = str.length;
for (var i = 0; i < bytesCount; i++) {
var ASCIINum = str.charCodeAt(i);
ASCIINum > 255 && bytesCount++;
}
return bytesCount;
}
arr.sort(function (a, b) {
return getBytesCount(b) - getBytesCount(a);
});
console.log(arr); // ['Coding2233', 'chifan', '抽yan', 'he酒', '烫头']