Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.4 KiB
Raw Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7b8c367417b2b2512b58 用 export default 创建一个默认导出 1 301199 create-an-export-fallback-with-export-default

--description--

export的课程中,学习了命名导出语法。这可以在其他文件中引用一些函数或者变量。

还需要了解另外一种被称为默认导出export的语法。在文件中只有一个值需要导出的时候,通常会使用这种语法。它也常常用于给文件或者模块创建返回值。

下面是一个简单的export default例子:

// named function
export default function add(x, y) {
  return x + y;
}

// anonymous function
export default function(x, y) {
  return x + y;
}

注意:当使用export default去声明一个文件或者模块的返回值时,在每个文件或者模块中应当只默认导出一个值。特别地,能将export deafultvarletconst一起使用。

--instructions--

下面的函数应该在这个模块中返回一个值。请添加需要的代码:

--hints--

正确的使用export进行返回。

assert(
  code.match(
    /export\s+default\s+function(\s+subtract\s*|\s*)\(\s*x,\s*y\s*\)\s*{/g
  )
);

--seed--

--seed-contents--

function subtract(x, y) {
  return x - y;
}

--solutions--

export default function subtract(x, y) {
  return x - y;
}