📝 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.
// ❌
const result = array.reverse().find(isUnicorn);
// ✅
const result = array.findLast(isUnicorn);// ❌
const result = array.toReversed().reduce(reducer, initialValue);
// ✅
const result = array.reduceRight(reducer, initialValue);