DEV Community

loading...

Discussion on: 5 Programming Patterns I Like

Collapse
xtofl profile image
xtofl • Edited

These patterns are so useful in day to day work!

In the 'one loop two arrays' pattern for partitioning I like to emphasize what is the essential, minimal difference in each condition. In this case, it's really just 'what array do I append to?'

var target =
  arrays[
    predicate(example) ? 1 : 0];
target.push(example);