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( "tapered" )
local append = require( "append" )

t.same( { 2, 4, 8 }, append( { 2, 4 }, 8 ) )
t.same( { 2, 4, 8, 16 }, append( { 2 }, 4, 8, 16 ) )

t.done()

See also