2.9 KiB
2.9 KiB
id, title, challengeType, forumTopicId, localeTitle
id | title | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|
587d7b7b367417b2b2512b17 | Combine Arrays with the Spread Operator | 1 | 301156 | Объединить массивы с оператором распространения |
Description
пусть thisArray = ['sage', 'rosemary', 'parsley', 'thyme'];Используя синтаксис распространения, мы только что выполнили операцию, которая была бы более сложной и более сложной, если бы мы использовали традиционные методы.
let thatArray = ['basil', 'cilantro', ... thisArray, 'coriander'];
// thisArray теперь равен ['basil', 'cilantro', 'sage', 'rosemary', 'parsley', 'thyme', 'coriander']
Instructions
spreadOut
которая возвращает sentence
переменной, модифицируйте функцию с помощью оператора спреда, чтобы он возвращал массив ['learning', 'to', 'code', 'is', 'fun']
.
Tests
tests:
- text: <code>spreadOut</code> should return <code>["learning", "to", "code", "is", "fun"]</code>
testString: assert.deepEqual(spreadOut(), ['learning', 'to', 'code', 'is', 'fun']);
- text: The <code>spreadOut</code> function should utilize spread syntax
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;
}