Imagine I have a list of objects that are Questions. I have to find if they are visible and if they are visible I have to change their answer to visible as well. (The example may not be practical it is just an example) If this is no side effect way (is it?):
questions.filter(function(question) {
return question.isVisible;
})
.map(function(visibleQuestion) {
return getAnswer(visibleQuestion);
})
.map(function(answer) {
answer.isVisible = true;
});
and this is side effect way:
questions.forEach(function(question) {
if (question.isVisible) {
var answer = getAnswer(visibleQuestion);
answer.isVisible = true;
}
});
Why choose the no side effect way if you have to iterate 3 times to do your job?
PS. I could be wrong of what is side effect and what is not and what really would be the two ways of handling this.