Search code examples
javascriptecmascript-6eslinteslint-config-airbnb

Stuck with eslint Error i.e Separately, loops should be avoided in favor of array iterations


I have the Code for some iterations and it works well. After installing eslint, One of my code generates an error by eslint.

My code is:

for (const column of columns) {
    for (const slugname of result[column.name]) {
        const alphabet = slugname.slugname;
        if (total[alphabet]) {
            total[alphabet] += column.value;
        } else {
            total[alphabet] = column.value;
        }
    }
}

eslint generates an error which is this

error iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations no-restricted-syntax

Any help or suggestion is really appreciated for that. According to me The code was written very precisely and very small, don't know about the clue of eslint error


Solution

  • columns.map(x => result[x.name].map((y) => {
      const alphabet = y.slugname;
      if (total[alphabet]) {
          total[alphabet] += x.value;
        } else {
          total[alphabet] = x.value;
        }
        return true;
    }));