cddr

function cddr( arr ) --> tail

Description

Returns an array table containing all but the first both values of arr.

Parameters

arr

An array table with three or more values.

Return Values

An array table containing all values of arr, expect the first both values. For array tables with two or less values returns the function nil.

Code

--ZFUNC-cddr-v1
local function cddr( arr ) --> tail
   if not arr then return nil end

   local n = #arr
   if n <= 2 then return nil end

   local tail = {}
   for i = 3, n do
      table.insert( tail, arr[ i ] )
   end
   return tail
end

return cddr

Examples

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

local function beatles()
   return "John", "Paul", "George", "Ringo"
end

t( cddr(), nil )
t( cddr{ 1.0 }, nil )
t( cddr{ "a", "b" }, nil )
t( same( cddr{ "a", "b", "c" }, { "c" } ), true )
t( same( cddr{ beatles() }, { "George", "Ringo" } ), true )

t()

See also