Back to all reviewers

Clear array operations

expressjs/express
Based on 2 comments
JavaScript

When working with arrays, prioritize clarity and explicitness over terse or clever constructs. For array membership checks, use `array.indexOf(item) === -1` rather than less obvious expressions like `!~array.indexOf(item)` or `array.indexOf(item) < 0`. This improves readability and makes code intent immediately clear to other developers.

Algorithms JavaScript

Reviewer Prompt

When working with arrays, prioritize clarity and explicitness over terse or clever constructs. For array membership checks, use array.indexOf(item) === -1 rather than less obvious expressions like !~array.indexOf(item) or array.indexOf(item) < 0. This improves readability and makes code intent immediately clear to other developers.

Be cautious with array manipulation methods that can cause unexpected behavior. The .concat() method can flatten arrays in unexpected ways:

// Potentially problematic:
[key].concat(fns)  // Will flatten if fns contains arrays

// More predictable alternatives:
[key, ...fns]      // ES6 spread syntax preserves structure
[].concat([key], fns)  // More explicit nesting

These practices ensure that array operations behave predictably and their intention is clear to anyone reading the code, which is especially important for search and manipulation algorithms.

2
Comments Analyzed
JavaScript
Primary Language
Algorithms
Category

Source Discussions