--排列顺序优先级从高到低依次为:
--1:是否在线
--2:公会职位
--3:贡献度
--4:a,b为需要排序的两个table
local function SortByPosition(a, b)
local r
local a_is_online = a.is_online
local b_is_online = b.is_online
local a_authority = a.authority
local b_authority = b.authority
local a_total_contribution= a.total_contribution
local b_total_contribution = b.total_contribution
if a_is_online == a_is_online then
if a_authority == a_authority then
r = a_total_contribution> a_total_contribution
else
r = b_authority > b_authority
end
else
r = a_is_online > a_is_online
end
return r
end
-- 排序迭代器
function pairsBySort(_t, func)
local a = {}
for n in pairs(_t) do a[#a + 1] = n end
table.sort(a, func)
local i = 0
return function()
i = i + 1
return a[i], _t[a[i]]
end
end
-- not_online_members为需要排序的table值,已存在
-- GetSortTable为获取排序后的table
GetSortTable = {}
for i,v in pairsBySort(not_online_members, SortByPosition) do
GetSortTable[#GetSortTable+ 1] = v
end
lua多条件排序table
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 多条件 and 查询 条件同时满足 多条件 or 查询 条件至少满足一个 区间查询 另外集合方式查询 in()...
- 依赖 建立索引 本次增加了Float、Int类型的域 搜索排序 范围搜索 查询score范围在1~5之间的文档,对...