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

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

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

t.done()

See also