Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 491
Aks Avatar asked Apr 25 '19 08:04

Aks


2 Answers

There is nothing wrong with your code, this is outdated guidance.

like image 25
reconbot Avatar answered Sep 21 '22 13:09

reconbot


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;
}));
like image 124
Aks Avatar answered Sep 18 '22 13:09

Aks