79560486

Date: 2025-04-07 17:39:48
Score: 2.5
Natty:
Report link

Here's the method I've used for years. This is not my original idea and I found it on StackOverflow. The reason why I use this specific approach is it because it allows me to keep things on one line, especially when using ternary methods where I want to control this or that flow of the logic. It allows you to keep everything in one line and instatiate the array on the fly. Very useful. Tried and true and I've been using it for years.

var exampleArray = [true, false, true, false];
(exampleArray .toString().match(/true/g) || []).length;

Reasons:
  • Blacklisted phrase (1): StackOverflow
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Alexander Dixon