Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 1.21 KB

File metadata and controls

34 lines (22 loc) · 1.21 KB

prefer-array-last-methods

📝 Prefer last-oriented array methods over Array#reverse() or Array#toReversed() followed by a method.

💼 This rule is enabled in the following configs: ✅ recommended, ☑️ unopinionated.

💡 This rule is manually fixable by editor suggestions.

Prefer last-oriented array methods over reversing an array and then calling the forward method.

This rule reports .reverse() and .toReversed() followed by .find(), .findIndex(), .indexOf(), or .reduce().

This rule only provides editor suggestions. The replacement can change observable behavior for mutation, sparse arrays, callback index or array arguments, and index-returning methods.

Examples

// ❌
const result = array.reverse().find(isUnicorn);

// ✅
const result = array.findLast(isUnicorn);
// ❌
const result = array.toReversed().reduce(reducer, initialValue);

// ✅
const result = array.reduceRight(reducer, initialValue);