Skip to content
Advertisement

Count the number of “trues” for n booleans

JavaScript

I would like to count the number of trues, each result should have its own associated action. Maybe something like:

JavaScript

Any idea of how to write the getResult method body a pretty way? In the example, I used only four, but it should be extendable to a bigger number of booleans. Any other way to proceed is welcome.

Advertisement

Answer

Write a variadic method?

JavaScript
Advertisement