append

function append( arr, v [, ...] ) --> arr

Description

Inserts one (v) or more () values to the array table arr at the end.

Parameters

arr

Array table that should be extended.

v

Value that should be append to the array table.

Additional values that also should be append to the array table.

Return Values

arr

Returns the extended array table.

Code

--ZFUNC-append-v1
local function append( arr, v, ... ) --> arr
   table.insert( arr, v )
   if ... then
      for i, o in ipairs{ ... } do
         table.insert( arr, o )
      end
   end
   return arr
end

return append

Example

local t = require( "taptest" )
local append = require( "append" )
local same = require( "same" )

arr = append( { 2, 4 }, 8 )
t( same( arr, { 2, 4, 8 } ), true )

arr = append( { 2 }, 4, 8, 16 )
t( same( arr, { 2, 4, 8, 16 } ), true )

t()

See also