2018-10-04 14:37:37 +01:00
---
id: 587d7daa367417b2b2512b6c
title: Combine an Array into a String Using the join Method
challengeType: 1
2020-05-21 17:31:25 +02:00
isHidden: false
2019-07-31 11:32:23 -07:00
forumTopicId: 18221
2018-10-04 14:37:37 +01:00
---
## Description
<section id='description'>
The <code>join</code> 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.
Here's an example:
2019-05-17 06:20:30 -07:00
```js
var arr = ["Hello", "World"];
var str = arr.join(" ");
// Sets str to "Hello World"
```
2018-10-04 14:37:37 +01:00
</section>
## Instructions
<section id='instructions'>
Use the <code>join</code> method (among others) inside the <code>sentensify</code> function to make a sentence from the words in the string <code>str</code>. 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 <code>replace</code> method.
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: Your code should use the <code>join</code> method.
2019-07-24 01:47:32 -07:00
testString: assert(code.match(/\.join/g));
2018-10-04 14:37:37 +01:00
- text: Your code should not use the <code>replace</code> method.
2020-03-26 20:13:34 +05:00
testString: assert(!code.match(/\.?[\s\S]*?replace/g));
2018-10-04 14:37:37 +01:00
- text: <code>sentensify("May-the-force-be-with-you")</code> should return a string.
2019-07-24 01:47:32 -07:00
testString: assert(typeof sentensify("May-the-force-be-with-you") === "string");
2018-10-04 14:37:37 +01:00
- text: <code>sentensify("May-the-force-be-with-you")</code> should return <code>"May the force be with you"</code>.
2019-07-24 01:47:32 -07:00
testString: assert(sentensify("May-the-force-be-with-you") === "May the force be with you");
2018-10-04 14:37:37 +01:00
- text: <code>sentensify("The.force.is.strong.with.this.one")</code> should return <code>"The force is strong with this one"</code>.
2019-07-24 01:47:32 -07:00
testString: assert(sentensify("The.force.is.strong.with.this.one") === "The force is strong with this one");
2018-10-20 21:02:47 +03:00
- text: <code>sentensify("There,has,been,an,awakening")</code> should return <code>"There has been an awakening"</code>.
2019-07-24 01:47:32 -07:00
testString: assert(sentensify("There,has,been,an,awakening") === "There has been an awakening");
2018-10-04 14:37:37 +01:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```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
}
sentensify("May-the-force-be-with-you");
```
</div>
</section>
## Solution
<section id='solution'>
```js
2019-04-28 02:01:14 -07:00
function sentensify(str) {
2020-03-08 07:46:28 -07:00
// Only change code below this line
2019-04-28 02:01:14 -07:00
return str.split(/\W/).join(' ');
2020-03-08 07:46:28 -07:00
// Only change code above this line
2019-04-28 02:01:14 -07:00
}
2018-10-04 14:37:37 +01:00
```
2019-07-18 08:24:12 -07:00
2018-10-04 14:37:37 +01:00
</section>