-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.lua
More file actions
38 lines (33 loc) · 796 Bytes
/
Copy pathUtils.lua
File metadata and controls
38 lines (33 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function countIf(table, predicate)
local res = 0
for i, val in pairs(table) do
if predicate == nil or predicate(val) then
res = res + 1
end
end
return res
end
function getSortedByValue(tbl, sortFunction)
local keys = {}
for key in pairs(tbl) do
table.insert(keys, key)
end
table.sort(keys, function(a, b)
return sortFunction(tbl[a], tbl[b])
end)
local res = {}
for i, key in ipairs(keys) do
table.insert(res, tbl[key])
end
return res
end
function max(tbl, func)
local highest = nil
for _, value in pairs(tbl) do
local val = func and func(value) or value
if highest == nil or highest < val then
highest = val
end
end
return highest
end