last

function last( arr ) --> val

Description

Returns the last element of arr.

Parameters

arr

An array table where we want the last element.

Return Values

val

The last element of the array table.

Code

--ZFUNC-last-v1
local function last( arr ) --> val
   return arr[ #arr ]
end

return last

Examples

local t = require( "taptest" )
local last = require( "last" )

arr = { "w", "x", "y", "z" }
t( last( arr ), "z" )

t()

Inspired by