Skip to content

Commit

Permalink
同步utility
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Aug 19, 2024
1 parent 7d2156d commit 1a9feda
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions script/utility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,21 @@ function m.sortCallbackOfIndex(arr)
end
end

---@param datas any[]
---@param scores integer[]
---@return SortByScoreCallback
function m.sortCallbackOfScore(datas, scores)
local map = {}
for i = 1, #datas do
local data = datas[i]
local score = scores[i]
map[data] = score
end
return function (v)
return map[v]
end
end

---裁剪字符串
---@param str string
---@param mode? '"left"'|'"right"'
Expand Down Expand Up @@ -851,12 +866,13 @@ function m.multiTable(count, default)
end })
end
for _ = 3, count do
local tt = current
current = setmetatable({}, { __index = function (t, k)
if k == nil then
return nil
end
t[k] = current
return current
t[k] = tt
return tt
end })
end
return current
Expand Down

0 comments on commit 1a9feda

Please sign in to comment.