sum

Modified on Thu, 9 Jul at 10:49 AM

sum

TABLE OF CONTENTS

Sum the numbers in an array

Definition

number sum(array[number] $array)

Sums all the elements of a number array. An error is raised if there is an element that is neither a number nor a boolean.

Parameters

array[number] $array

An array to sum the elements of.

Returns

number

The sum of all the elements of $array.

Examples

Transformation
{
  a: sum(`[1, 2, 3]`),
  b: sum(`[-1, -2, 3]`),
  c: sum(`[1.0, -2.5, 3.1]`),
  d: sum(`[true, false, 0]`),
  e: sum(`[]`),
  f: sum(['string',`1`,`0`])       // Error
}
Result
{
  "a": 6,
  "b": 0,
  "c": 1.6,
  "d": 1,
  "e": 0
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article