Open main menu
Home
Random
Nearby
Log in
Settings
About Kancolle Wiki
Disclaimers
Kancolle Wiki
Search
Changes
← Older edit
Newer edit →
Module:Core
(view source)
Revision as of 14:38, 4 June 2019
378 bytes added
,
5 years ago
no edit summary
Line 15:
Line 15:
-- * Collection functions.
-- * Collection functions.
+
+
function Utils.isArray(xs)
+
for k, _ in pairs(xs) do
+
return k == 1
+
end
+
return true
+
end
+
+
function Utils.findBy(xs, p)
+
if Utils.isArray(xs) then
+
for k, v in ipairs(xs) do
+
if p(v, k) then
+
return v, k
+
end
+
end
+
else
+
for k, v in pairs(xs) do
+
if p(v, k) then
+
return v, k
+
end
+
end
+
end
+
return nil
+
end
function Utils.find(tbl, v_, k_)
function Utils.find(tbl, v_, k_)
がか
cssedit, gkautomate
7,064
edits