* 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>
1.7 KiB
1.7 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7b88367417b2b2512b44 | 编写带参数的箭头函数 | 1 | 301223 | write-arrow-functions-with-parameters |
--description--
和一般的函数一样,你也可以给箭头函数传递参数。
// 给传入的数值乘以 2 并返回结果
const doubler = (item) => item * 2;
如果箭头函数只有一个参数,则可以省略包含该参数的括号。
// the same function, without the argument parentheses
const doubler = item => item * 2;
可以将多个参数传递到箭头函数中。
// multiplies the first input value by the second and returns it
const multiplier = (item, multi) => item * multi;
--instructions--
使用箭头函数的语法重写myConcat
函数,使其可以将arr2
的内容填充在arr1
里。
--hints--
替换掉所有的var
关键字。
(getUserInput) => assert(!getUserInput('index').match(/var/g));
myConcat
应该是一个常量 (使用const
)。
(getUserInput) => assert(getUserInput('index').match(/const\s+myConcat/g));
myConcat
应该是一个函数。
assert(typeof myConcat === 'function');
myConcat()
应该返回 [1, 2, 3, 4, 5]
。
assert(() => {
const a = myConcat([1], [2]);
return a[0] == 1 && a[1] == 2;
});
不要使用function
关键字。
(getUserInput) => assert(!getUserInput('index').match(/function/g));
--seed--
--seed-contents--
var myConcat = function(arr1, arr2) {
return arr1.concat(arr2);
};
console.log(myConcat([1, 2], [3, 4, 5]));
--solutions--
const myConcat = (arr1, arr2) => {
return arr1.concat(arr2);
};
console.log(myConcat([1, 2], [3, 4, 5]));