Add elements of array in jsonnet

1.3k views Asked by At

I am trying to add elements of an array in jsonnet. Can someone post a sample?

Sample input: [0, 1, 2, 3]

output 6

1

There are 1 answers

1
jjo On BEST ANSWER

You can use std.foldl() as the "aggregation" function:

local myArray = [0, 1, 2, 3];

std.foldl(function(x, y) (x + y), myArray, 0)