2.0 KiB
2.0 KiB
id, challengeType, forumTopicId, localeTitle
id | challengeType | forumTopicId | localeTitle |
---|---|---|---|
587d7b7b367417b2b2512b17 | 1 | 301156 | 组合使用数组和扩展运算符 |
Description
let thisArray = ['sage', 'rosemary', 'parsley', 'thyme'];
let thatArray = ['basil', 'cilantro', ...thisArray, 'coriander'];
// thatArray 现在是 ['basil', 'cilantro', 'sage', 'rosemary', 'parsley', 'thyme', 'coriander']
使用展开语法,我们这样就实现了一个用传统方法要写得很复杂冗长的操作。
Instructions
sentence
变量的spreadOut
函数,请修改该函数,利用展开运算符使该函数返回数组['learning', 'to', 'code', 'is', 'fun']
。
Tests
tests:
- text: '<code>spreadOut</code>应该返回<code>["learning", "to", "code", "is", "fun"]</code>'
testString: assert.deepEqual(spreadOut(), ['learning', 'to', 'code', 'is', 'fun']);
- text: <code>spreadOut</code>函数里应该用到展开语法
testString: assert.notStrictEqual(spreadOut.toString().search(/[...]/), -1);
Challenge Seed
function spreadOut() {
let fragment = ['to', 'code'];
let sentence; // change this line
return sentence;
}
// do not change code below this line
console.log(spreadOut());
Solution
// solution required
function spreadOut() {
let fragment = ['to', 'code'];
let sentence = ['learning', ...fragment, 'is', 'fun'];
return sentence;
}