updatearray with foreach

How do i retain updated array's positional values during each iteration of foreach ?

Example :

Trying to update second and third index to 1 depending on the rule input

ri!selectedMonths -> {2,3}

desired result -> {0,1,1,0,0,0,0,0,0,0,0,0}

 

load(

local!allmonths:index({},enumerate(12),0),
 

a!forEach(
  items: ri!selectedMonths,
  expression:
  fn!updatearray(local!allmonths,fv!item,1)

)
)

 

The result of the rule repeats itself for every execution without retaining the value from previous execution.

Second execution updates second index position , third execution updates third position but reevaluates the array without retaining value from second execution.

  Discussion posts and replies are publicly visible