--- id: 587d7daa367417b2b2512b6c title: Combine an Array into a String Using the join Method challengeType: 1 videoUrl: '' localeTitle: 使用join方法将Array组合成String --- ## Description
join方法用于将数组的元素连接在一起以创建字符串。它需要一个用于分隔字符串中数组元素的分隔符的参数。这是一个例子:
var arr = [“你好”,“世界”];
var str = arr.join(“”);
//将str设置为“Hello World”
## Instructions
使用sentensify函数内的join方法(以及其他方法)从字符串str的单词创建一个句子。该函数应返回一个字符串。例如,“我喜欢星球大战”将被转换为“我喜欢星球大战”。对于此挑战,请勿使用replace方法。
## Tests
```yml tests: - text: 您的代码应使用join方法。 testString: 'assert(code.match(/\.join/g), "Your code should use the join method.");' - text: 您的代码不应使用replace方法。 testString: 'assert(!code.match(/\.replace/g), "Your code should not use the replace method.");' - text: sentensify("May-the-force-be-with-you")应该返回一个字符串。 testString: 'assert(typeof sentensify("May-the-force-be-with-you") === "string", "sentensify("May-the-force-be-with-you") should return a string.");' - text: sentensify("May-the-force-be-with-you")应该返回"May the force be with you" 。 testString: 'assert(sentensify("May-the-force-be-with-you") === "May the force be with you", "sentensify("May-the-force-be-with-you") should return "May the force be with you".");' - text: sentensify("The.force.is.strong.with.this.one")应该返回"The force is strong with this one" 。 testString: 'assert(sentensify("The.force.is.strong.with.this.one") === "The force is strong with this one", "sentensify("The.force.is.strong.with.this.one") should return "The force is strong with this one".");' - text: 'sentensify("There,has,been,an,awakening")应该回归"There has been an awakening" 。' testString: 'assert(sentensify("There,has,been,an,awakening") === "There has been an awakening", "sentensify("There,has,been,an,awakening") should return "There has been an awakening".");' ```
## Challenge Seed
```js function sentensify(str) { // Add your code below this line // Add your code above this line } sentensify("May-the-force-be-with-you"); ```
## Solution
```js // solution required ```