This is a nice primer for beginners, but I disagree with the suggestion that reduce is inherently better than a traditional looping structure. Suggesting the latter naturally results in mutated values or side effects is simply false. Reduce doesn't inherently protect you against either. Also, if performance is important, native loops tend to perform better by at least one order of magnitude than functional style; this is typically attributed to function call overhead.
Thanks and you are right, reduce is not inherently better than a for loop. And if you use a for loop the right way, you are still able to write your code based on the functional programming principles, and if performance is really important it's better to use a for loop. I agree on all these arguments. So I changed the content of the blog to nuance the content of my earlier statements. Thanks for your contribution.
Hi, agree, no need to use reduce each time when in certain or most situations we can use other methods, but, regarding the performance, the reduce method is much faster when handling big data. For example, we can "filter" and "map" all in one step with "reduce", with it we can iterate just once.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a nice primer for beginners, but I disagree with the suggestion that reduce is inherently better than a traditional looping structure. Suggesting the latter naturally results in mutated values or side effects is simply false. Reduce doesn't inherently protect you against either. Also, if performance is important, native loops tend to perform better by at least one order of magnitude than functional style; this is typically attributed to function call overhead.
Thanks and you are right, reduce is not inherently better than a for loop. And if you use a for loop the right way, you are still able to write your code based on the functional programming principles, and if performance is really important it's better to use a for loop. I agree on all these arguments. So I changed the content of the blog to nuance the content of my earlier statements. Thanks for your contribution.
Hi, agree, no need to use reduce each time when in certain or most situations we can use other methods, but, regarding the performance, the reduce method is much faster when handling big data. For example, we can "filter" and "map" all in one step with "reduce", with it we can iterate just once.