卡在eslint错误中,即应避免使用数组迭代来避免循环

时间:2019-04-25 08:07:05

标签: javascript ecmascript-6 eslint eslint-config-airbnb

我有一些迭代的代码,并且效果很好。安装eslint之后,我的其中一个代码因eslint生成了一个错误。

我的代码是:

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生成一个错误

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

为此,我们将不胜感激任何帮助或建议。据我说,代码编写得非常精确而且很小,不知道eslint错误的线索

1 个答案:

答案 0 :(得分:0)

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;
}));