sum

function sum( x, ... ) --> res

Description

Computes the sum of x with all the additional values ().

Parameters

x

The first number you want to add to the sum.

An variable number of values that will be added to x.

Return Values

res

The calculated sum value.

Code

--ZFUNC-sum-v1
local function sum( x, ... ) --> res
   local res = x
   for _, v in ipairs{ ... } do
      res = res + v
   end
   return res
end

return sum

Examples

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

t( sum( 10, 10, 10 ), 30 )
t( sum( 20, -2, 3 ), 21 )

t()