help to create rule to calculate data based on the previous iteration

Certified Associate Developer
I have this array {100, 50, 20,50,10} and a variable x = 600, I need help to create a rule that creates an array with the results that must be calculated in this way:

The first value of the array must be subtracted with the variable x, the result must be subtracted with the second value of the array, the previous result must be subtracted with the third position and so on. The results must be stored in an array.

At the moment I have this code but it does not work correctly


a!localVariables(
local!regularizaciones: {100, 50, 20,50,10},
local!initialValue: 600,


local!resultArray: {local!initialValue},

a!forEach(
items: a!forEach(
items: local!array,
expression: fv!item
),
expression: a!localVariables(
local!currentValue: fv!item,
local!lastResult: index(local!resultArray, length(local!resultArray)),
local!newResult: local!lastResult - local!currentValue,
local!resultArray: append(local!resultArray, local!newResult)
)
),


local!resultArray

)

I appreciate any help


  Discussion posts and replies are publicly visible

Parents Reply Children
No Data