I've been thinking about switch statements that collect a value so it can be returned at the end. imagine this ... which does not work for a few reasons.
The idea is to collect the result, then return it at the end. I'm not fond of this type of code with the let up top and then making sure each case handles a value. Any thoughts on what you do here?
Reading this again (it's good, well done Bryan!).
I've been thinking about switch statements that collect a value so it can be returned at the end. imagine this ... which does not work for a few reasons.
The idea is to collect the result, then return it at the end. I'm not fond of this type of code with the
let
up top and then making sure each case handles a value. Any thoughts on what you do here?This is a great insight! I combined this with a post above and created a little helper module: npmjs.com/package/conditional-reduce
Code looks like:
So with that ... the code would be somehtng like this, for the example you and I used first. RIght?
A few syntax issues aside, yes ;-)
It would look like:
yeah, i figured the dev.to editor wouldn't protect me and that you'd forgive those mistakes :)