What's difference between “reduce” and “scan”

前端 未结 3 1158
孤独总比滥情好
孤独总比滥情好 2021-02-12 09:21

I\'m studying RXJS and stuck with the problem: the same code with operators \"reduce\" and \"scan\" works in different ways, but I think that must return equal result. Example b

3条回答
  •  旧时难觅i
    2021-02-12 10:05

    there almost the same but scan emits each iteration. and reduce just emits a final results. i like scan when i want to actually see what reduce is doing. so sometimesi . use reduce and i cant visualize what reduce is actually doing. in this case i simple swap out reduce for scan since it will emit on each iteration. this way i can put in a log statement and see the results for each iteration.

提交回复
热议问题