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

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

t.done()