Skip to content
Lists & Helpers arrayReduce

$arrayReduce — Folds an array to one value: the code returns the new accumulator.

Folds an array to one value: the code returns the new accumulator.

Syntax

$arrayReduce[array;accumulator;item;code;(start)]

Parameters

  • array (text, required) — Name of the array.
  • accumulator (text, required) — Local variable that holds the accumulator.
  • item (text, required) — Local variable that holds the item.
  • code (code, required) — Code returning the new accumulator.
  • start (number, optional) — Start value (default 0).

Return Value

  • string.

Usage

$arrayReduce[a;t;x;$sum[$env[t];$env[x]]] → "6"

Example

$sendMessage[$arrayReduce[a;t;x;$sum[$env[t];$env[x]]]]

Try it

Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.