DEV Community

Discussion on: Which Array Function When?

Collapse
 
belethcz profile image
Jaromír Franek

If i would ever seen such code i would instantly decline any pull request this may be contained in.
Do you seriously mean that it make it simpler in any way? I have been programing node.js apps for a 3 years now and seen some horrible things done in sake of simplicity and performance and this may be one of those. What if acumulator have started as -1 for some reason? You would have never change it in the end.

Collapse
 
erickjth profile image
Erick Torres • Edited

You are right, when accumulator stars in -1, it'll fail. When I said much simpler, I meant simpler in terms of writing code. :D

Thread Thread
 
billbarron profile image
Bill Barron

Protip: Don't try to be clever with your code:

simplethread.com/dont-be-clever/

Collapse
 
michie1 profile image
michie1

I understand how the ternary and the logical operators work, and still I agree with you that it doesn't make it "simpler". If and else takes some more lines of code, but it's more easy to debug, refactor, document compared to single line expressions.