2018-10-04 13:37:37 +00:00
---
id: 587d7daa367417b2b2512b6c
title: Combine an Array into a String Using the join Method
challengeType: 1
2019-07-31 18:32:23 +00:00
forumTopicId: 18221
2021-01-13 02:31:00 +00:00
dashedName: combine-an-array-into-a-string-using-the-join-method
2018-10-04 13:37:37 +00:00
---
2020-11-27 18:02:05 +00: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 13:37:37 +00:00
Here's an example:
2019-05-17 13:20:30 +00:00
```js
var arr = ["Hello", "World"];
var str = arr.join(" ");
```
2021-03-03 00:12:12 +00:00
`str` would have a value of the string `Hello World` .
2020-11-27 18:02:05 +00:00
# --instructions--
2021-03-03 00:12:12 +00: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 18:02:05 +00: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-03 00:12:12 +00:00
`sentensify("May-the-force-be-with-you")` should return the string `May the force be with you` .
2018-10-04 13:37:37 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(sentensify('May-the-force-be-with-you') === 'May the force be with you');
2018-10-04 13:37:37 +00:00
```
2021-03-03 00:12:12 +00:00
`sentensify("The.force.is.strong.with.this.one")` should return the string `The force is strong with this one` .
2018-10-04 13:37:37 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(
sentensify('The.force.is.strong.with.this.one') ===
'The force is strong with this one'
);
```
2018-10-04 13:37:37 +00:00
2021-03-03 00:12:12 +00:00
`sentensify("There,has,been,an,awakening")` should return the string `There has been an awakening` .
2020-11-27 18:02:05 +00:00
```js
assert(
sentensify('There,has,been,an,awakening') === 'There has been an awakening'
);
```
# --seed--
## --seed-contents--
2018-10-04 13:37:37 +00:00
```js
function sentensify(str) {
2020-03-08 14:46:28 +00:00
// Only change code below this line
2018-10-08 00:01:53 +00:00
2020-03-08 14:46:28 +00:00
// Only change code above this line
2018-10-04 13:37:37 +00:00
}
sentensify("May-the-force-be-with-you");
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-10-04 13:37:37 +00:00
```js
2019-04-28 09:01:14 +00:00
function sentensify(str) {
2020-03-08 14:46:28 +00:00
// Only change code below this line
2019-04-28 09:01:14 +00:00
return str.split(/\W/).join(' ');
2020-03-08 14:46:28 +00:00
// Only change code above this line
2019-04-28 09:01:14 +00:00
}
2018-10-04 13:37:37 +00:00
```