Skip to content

avoid-reverse is wrong #68

Closed
Closed
@fregante

Description

@fregante

Readme example:

const sum = array.reverse().reduce((p, c) => p + c, 0);
const reverseSum = array.reverse().reduceRight((p, c) => p + c, 0);

The sums are a bad example since their order doesn't matter. Try this:

['a','b','c'].reverse().reduce((p, c) => p + c, '');
// 'cba'
['a','b','c'].reverse().reduceRight((p, c) => p + c, '');
// 'abc'
['a','b','c'].reduce((p, c) => p + c, '');
// 'abc'
['a','b','c'].reduceRight((p, c) => p + c, '');
// 'cba'

Did you mean to replace .reverse().reduce() with .reduceRight() and vice-versa instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions