【问题标题】:Getting invalid regular expression flag after running the program运行程序后获取无效的正则表达式标志
【发布时间】:2018-07-24 11:30:06
【问题描述】:

我在 freeCodeCamp 上练习 ES6。目前,我正在解决与主题模板文字相关的问题。问题陈述就像

使用带有 backticks 的模板文字语法来显示 result 对象的 failure 数组的每个条目。每个条目都应包含在具有类属性 text-warningli 元素中,并列在 resultDisplayArray 中。

执行代码后,所有测试用例都通过,除了一个

使用了模板字符串

我得到了错误

无效的正则表达式标志

请看下面的代码,告诉我哪里做错了。

const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["id-blacklist", "no-dup-keys"]
};
function makeList(arr) {
  "use strict";

  // change code below this line
  const resultDisplayArray = arr.map(value => 
  `<li class="text-warning">${value}</li>`);
  // change code above this line

  return resultDisplayArray;
}
/**
 * makeList(result.failure) should return:
 * [ <li class="text-warning">no-var</li>,
 *   <li class="text-warning">var-on-top</li>, 
 *   <li class="text-warning">linebreak</li> ]
 **/
const resultDisplayArray = makeList(result.failure);

【问题讨论】:

  • 我已经在控制台中测试了你的代码,它工作正常,没有错误,显示的结果和你提到的一样。
  • 感谢@Karan 的回复,但所有测试用例都没有通过 freeCodeCamp。能不能在平台上试一下。这是链接learn.freecodecamp.org/…
  • 它也对我有用。问题是开发者控制台还是 CodeCamp 本身?
  • @dandeto codeCamp 本身。
  • 看来是freeCodeCamp的bug。你的代码是正确的。而且您根本没有使用正则表达式(因此正则表达式标志不能不正确!)。向他们报告这个错误。

标签: ecmascript-6


【解决方案1】:

您的代码正确且清晰!

这是 freeCodeCamp 的一个错误,您可以在 GitHub thread 上看到。

干杯

【讨论】:

  • 谢谢@Guilherme
  • 欢迎我的朋友@VivekKumar
猜你喜欢
  • 2020-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-30
  • 2021-06-07
  • 2020-11-14
相关资源
最近更新 更多