2.0 KiB
2.0 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
587d7b7b367417b2b2512b17 | Combine Arrays with the Spread Operator | 1 | 301156 |
Description
let thisArray = ['sage', 'rosemary', 'parsley', 'thyme'];
let thatArray = ['basil', 'cilantro', ...thisArray, 'coriander'];
// thatArray now equals ['basil', 'cilantro', 'sage', 'rosemary', 'parsley', 'thyme', 'coriander']
Using spread syntax, we have just achieved an operation that would have been more complex and more verbose had we used traditional methods.
Instructions
spreadOut
that returns the variable sentence
. Modify the function using the spread operator so that it returns the array ['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;
}
console.log(spreadOut());
Solution
function spreadOut() {
let fragment = ['to', 'code'];
let sentence = ['learning', ...fragment, 'is', 'fun'];
return sentence;
}