What is the "context" parameter in reduce()

Certified Senior Developer

Can someone explain with an example the reducefunction, initial, list, context ) function's "context " parameter. I didn't find an example for it in the docs.

  Discussion posts and replies are publicly visible

Parents
  • Hi there,

    I tried implementing various cases of it below for my understanding. 

    If we examine the pattern below, it looks like the context is being passed in every evaluation as an extra value along with the initial and respective item from the list. 
    Ex. In the expression on line 4, you can see that the result has been increased by 3. This means that the value in 'context' was passed in the function along with the other 2 values, every time the reduce did an iteration. You can find a similar pattern in other expressions written in the above image. 

Reply
  • Hi there,

    I tried implementing various cases of it below for my understanding. 

    If we examine the pattern below, it looks like the context is being passed in every evaluation as an extra value along with the initial and respective item from the list. 
    Ex. In the expression on line 4, you can see that the result has been increased by 3. This means that the value in 'context' was passed in the function along with the other 2 values, every time the reduce did an iteration. You can find a similar pattern in other expressions written in the above image. 

Children
No Data