2018-10-04 14:37:37 +01:00
---
id: 587d7daa367417b2b2512b6c
title: Combine an Array into a String Using the join Method
challengeType: 1
2019-07-31 11:32:23 -07:00
forumTopicId: 18221
2021-01-13 03:31:00 +01:00
dashedName: combine-an-array-into-a-string-using-the-join-method
2018-10-04 14:37:37 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
The `join` method is used to join the elements of an array together to create a string. It takes an argument for the delimiter that is used to separate the array elements in the string.
2018-10-04 14:37:37 +01:00
Here's an example:
2019-05-17 06:20:30 -07:00
```js
2021-10-26 01:55:58 +09:00
const arr = ["Hello", "World"];
const str = arr.join(" ");
2019-05-17 06:20:30 -07:00
```
2021-03-02 16:12:12 -08:00
`str` would have a value of the string `Hello World` .
2020-11-27 19:02:05 +01:00
# --instructions--
2021-03-02 16:12:12 -08:00
Use the `join` method (among others) inside the `sentensify` function to make a sentence from the words in the string `str` . The function should return a string. For example, `I-like-Star-Wars` would be converted to `I like Star Wars` . For this challenge, do not use the `replace` method.
2020-11-27 19:02:05 +01:00
# --hints--
Your code should use the `join` method.
```js
assert(code.match(/\.join/g));
```
Your code should not use the `replace` method.
```js
assert(!code.match(/\.?[\s\S]*?replace/g));
```
`sentensify("May-the-force-be-with-you")` should return a string.
```js
assert(typeof sentensify('May-the-force-be-with-you') === 'string');
```
2021-03-02 16:12:12 -08:00
`sentensify("May-the-force-be-with-you")` should return the string `May the force be with you` .
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(sentensify('May-the-force-be-with-you') === 'May the force be with you');
2018-10-04 14:37:37 +01:00
```
2021-03-02 16:12:12 -08:00
`sentensify("The.force.is.strong.with.this.one")` should return the string `The force is strong with this one` .
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(
sentensify('The.force.is.strong.with.this.one') ===
'The force is strong with this one'
);
```
2018-10-04 14:37:37 +01:00
2021-03-02 16:12:12 -08:00
`sentensify("There,has,been,an,awakening")` should return the string `There has been an awakening` .
2020-11-27 19:02:05 +01:00
```js
assert(
sentensify('There,has,been,an,awakening') === 'There has been an awakening'
);
```
# --seed--
## --seed-contents--
2018-10-04 14:37:37 +01:00
```js
function sentensify(str) {
2020-03-08 07:46:28 -07:00
// Only change code below this line
2018-10-08 01:01:53 +01:00
2020-03-08 07:46:28 -07:00
// Only change code above this line
2018-10-04 14:37:37 +01:00
}
2021-10-26 01:55:58 +09:00
2018-10-04 14:37:37 +01:00
sentensify("May-the-force-be-with-you");
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-10-04 14:37:37 +01:00
```js
2019-04-28 02:01:14 -07:00
function sentensify(str) {
return str.split(/\W/).join(' ');
}
2018-10-04 14:37:37 +01:00
```