MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/mwcaao/ternary_operators_at_their_maximum_potential/h175ts6/?context=3
r/badcode • u/SpeckyYT sadistic • Apr 22 '21
73 comments sorted by
View all comments
2
Not a JS dev, not sure if the reduce signature is correct
['run', 'fire', 'execute', 'callback'].reduce(null, (acc, k) => acc || cmd[k])
2 u/SpeckyYT sadistic Jun 09 '21 I don't think anyone would ever come on this idea, but that works quite well..reduce takes as first parameter the function, so you shouldn't add the null. 2 u/Sp1um Jun 09 '21 The null is supposed to be the accumulator initial value 2 u/SpeckyYT sadistic Jun 10 '21 The accumulator's initial value can be optionally set as the second parameter.
I don't think anyone would ever come on this idea, but that works quite well.
.reduce takes as first parameter the function, so you shouldn't add the null.
.reduce
null
2 u/Sp1um Jun 09 '21 The null is supposed to be the accumulator initial value 2 u/SpeckyYT sadistic Jun 10 '21 The accumulator's initial value can be optionally set as the second parameter.
The null is supposed to be the accumulator initial value
2 u/SpeckyYT sadistic Jun 10 '21 The accumulator's initial value can be optionally set as the second parameter.
The accumulator's initial value can be optionally set as the second parameter.
2
u/Sp1um Jun 09 '21
Not a JS dev, not sure if the reduce signature is correct