So let’s say you have this say(msg) function:

And you want to call it with different parameters in series. What would you do?

Of course, you can always chain up the promises like so:

But for more input parameters, this is super tedious and hard to read. So instead, we can use the reduce function creatively to achieve the same goal elegantly:

Note that the last parameter pass to reduce is treated as the initial value for the reduce, so essentially the above code is equal to:

A even better way would be refactoring the original say(msg) function:

Then we can use it as: