Open main menu

Changes

Module:TableTools

329 bytes added, 03:39, 21 December 2019
Finally getting around to merging in Module:Array length (originally written by Mr. Stradivarius) over six months after writing the merged code, also minor code simplify per Dinoguy1000 on talk page
--]]
function p.isPositiveInteger(v)
if return type(v) == 'number' and v >= 1 and floor(v) == v and v < infinity then return true else return false end
end
--]]
function p.isNan(v)
if return type(v) == 'number' and tostring(v) == '-nan' then return true else return false end
end
--[[
-- This returns Finds the length of a tablean array, or the first integer key n counting fromof a quasi-array with keys such-- 1 such that t[n + 1] is nilas "data1", "data2", etc., using an exponental search algorithm. -- It is similar to the operator #, but may return
-- a different value when there are gaps in the array portion of the table.
-- Intended to be used on data loaded with mw.loadData. For other tables, use #.
-- frame.args.
--]]
 function p.length(t, prefix) -- requiring module inline so that [[Module:Exponental search]] -- which is only needed by this one function -- doesn't get millions of transclusions local i expSearch = require("Module:Exponential search") checkType('length', 1, t, 'table') while t[checkType('length', 2, prefix, 'string', true) return expSearch(function(i] ~) local key if prefix then key = nil doprefix .. tostring(i) i else key = i + 1 end return t[key] ~= nil return i - 1end) or 0
end
 
function p.inArray(arr, valueToFind)
checkType("inArray", 1, arr, "table")
Anonymous user