thingsdb / ThingsDB

Node - The ThingsDB Core
https://thingsdb.io
GNU General Public License v3.0
42 stars 3 forks source link

Sum #354

Closed joente closed 1 year ago

joente commented 1 year ago

Description

Add function sum (sum all elements of a list).

Similar behavior could be achieved using the reduce function but this is more difficult to read.

Example:

range(10).reduce(|i, t| i+ t, 0);  // 45
// versus
range(10).sum();  // 45

Another example with callback:

[{x: 1, x: 2}].reduce(|o, t| t + o.x, 0);  // 3
// versus
[{x: 1, x: 2}].sum(|o| o.x);  // 3

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Checklist: