sk_225 sk_225 - 1 month ago 17
Javascript Question

ESLint Error: prefer-arrow-callback on the reduce method?

I'm getting an the "prefer-arrow-method" eslint error thrown with the reduce function below. I know it's because the function is anonymous but how would I rewrite the reduce method to resolve this error?

const nameBrand =
names.brand().reduce(function (sum, name) {
sum[name] = name;
return sum;
}, {});

Answer Source
const nameBrand = names.brand().reduce((sum, name) => {
    sum[name] = name;
    return sum;
}, {});