function sort(list, field, order) {
list.sort((a, b) => {
let af = a[field] || 0;
let bf = b[field] || 0;
if (!isNaN(af) && !isNaN(bf)) {
switch (order) {
case 'desc':
return +bf - +af;
default:
return +af - +bf;
}
}
let aid = af.split('');
let bid = bf.split('');
let c = aid.length > bid.length ? aid.length : bid.length;
for (let index = 0; index < c; index++) {
let ac = aid[index] ? aid[index].charCodeAt() : 0;
let bc = bid[index] ? bid[index].charCodeAt() : 0;
if (ac != bc) {
switch (order) {
case 'desc':
return bc - ac;
default:
return ac - bc;
}
}
}
return 0;
})
}