[Solved] How to deal with Unexpected use of comma operator no-sequences EsLINT warning

I am getting an eslint warning for unexpected use of comma. I found this answer but it does not match my issue.

I have this code

const reduced = _.map(_.keys(grouped), function(e) {
        return _.reduce(grouped[e], function(r, o) {
          return r.count += +o.amount, r
        }, {price: parseFloat(e), count: 0, amount: e.amount})

How do I get rid of the warning? Thank you very much.

Solution #1:

Your return statement in the .reduce callback can be written as

  r.count += +o.amount;
  return r;

That does exactly the same thing, but it should make ESLint happy.

Respondent: Pointy

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.