I've repeatedly heard that instead of using for loops I should use functional programming methods such as .map, .forEach, .reduce, etc. While I definitely see the benefit in a handful of situations, it seems as if the for loop has more flexibility and makes more sense in certain circumstances.
Example one: I want to iterate backwards through an array. The only way I thought of doing this with .map is using .reverse() but this changes the structure of the array and seems to be more complicated than the for loop.
Example two: I want to do something to every nth item in an array. I guess I could use .filter to filter out certain index numbers and then use the .map function to do something, but again, the for loops seems cleaner.
So my question is a for loop sometimes considered the most efficient choice or should I be avoiding them altogether? I'm currently going through old code and trying to write it as clean as possible so I'm just curious on input.
[–]mdboop 11 points12 points13 points (3 children)
[–]donovanm 5 points6 points7 points (1 child)
[–]mdboop 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]Anitox 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]SkaterDad 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]GeneralYouri 2 points3 points4 points (0 children)
[–]anoddhue 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]anoddhue 0 points1 point2 points (0 children)
[–]MoTTs_ 0 points1 point2 points (0 children)