Modul:Array: Unterschied zwischen den Versionen

Aus FürthWiki

Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 2: Zeile 2:


function p.contains(list, str)
function p.contains(list, str)
-- returns true if the list contains the str, but false if not
for i, v in ipairs(list) do
for i, v in ipairs(list) do
if v == str then
if v == str then

Version vom 24. August 2025, 12:14 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Array/Doku erstellt werden

p = {}

function p.contains(list, str)
	-- returns true if the list contains the str, but false if not
	for i, v in ipairs(list) do
		if v == str then
			return true
		end
	end
	return false
end

function p.merge(t1, t2)
	-- merge tables that are arrays: {1,2,3} and {3,4,5}
    local result = {}
    for i = 1, #t1 do
        table.insert(result, t1[i])
    end
    for i = 1, #t2 do
        table.insert(result, t2[i])
    end
    return result
end

return p