table.sort(list) //默认按照升序排序,但是当存在相等比较时,每次调用后顺序会不定
--自定义排序规则
table.sort(list,function(a,b)
if(a.num > b.num) then
return true --num降序
elseif(a.num == b.num) then
if(a.count < b.count) then
return true --count 升序
elseif(a.count == b.count) then
return a.id > b.id --id降序
end
return false
end)
Lua - table.sort 排序
最新推荐文章于 2024-05-23 21:41:49 发布
文章介绍了如何在JavaScript中使用table.sort方法进行自定义排序,当元素相等时,通过num、count和id属性进行递归排序,实现降序、升序的复杂需求。
2万+

被折叠的 条评论
为什么被折叠?



