cdr
function cdr( arr ) --> tail
Description
Returns an array table containing all but the first value of arr.
Parameters
- arr
-
An array table with two or more values.
Return Values
- tail
-
An array table containing all values of arr, expect the first value. For an empty array table and for array tables with just one value returns the function nil.
Code
--ZFUNC-cdr-v1 local function cdr( arr ) --> tail if not arr then return nil end local n = #arr if n <= 1 then return nil end local tail = {} for i = 2, n do table.insert( tail, arr[ i ] ) end return tail end return cdr
Examples
local t = require( "taptest" ) local cdr = require( "cdr" ) local same = require( "same" ) local function beatles() return "John", "Paul", "George", "Ringo" end t( cdr(), nil ) t( cdr{ 1.0 }, nil ) t( same( { "b" }, cdr{ "a", "b" }, { "b" } ), true ) t( same( cdr{ "a", "b", "c" }, { "b", "c" } ), true ) t( same( cdr{ beatles() }, { "Paul", "George", "Ringo" } ), true ) t()