freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../functional-programming/combine-an-array-into-a-str...

1.5 KiB

id title challengeType forumTopicId
587d7daa367417b2b2512b6c 使用 join 方法将数组组合成字符串 1 18221

--description--

join方法用来把数组中的所有元素放入一个字符串,并通过指定的分隔符参数进行分隔。

举个例子:

var arr = ["Hello", "World"];
var str = arr.join(" ");
// Sets str to "Hello World"

--instructions--

在函数sentensify内用join方法(及其他方法)用字符串str中的单词造句,这个函数应返回一个字符串。举个例子,"I-like-Star-Wars" 会被转换成 "I like Star Wars"。在此挑战中请勿使用replace方法。

--hints--

应使用join方法。

assert(code.match(/\.join/g));

不能使用replace方法。

assert(!code.match(/\.replace/g));

sentensify('May-the-force-be-with-you')应返回一个字符串

assert(typeof sentensify('May-the-force-be-with-you') === 'string');

sentensify('May-the-force-be-with-you')应返回'May the force be with you'

assert(sentensify('May-the-force-be-with-you') === 'May the force be with you');

sentensify('The.force.is.strong.with.this.one')应返回'The force is strong with this one'

assert(
  sentensify('The.force.is.strong.with.this.one') ===
    'The force is strong with this one'
);

sentensify('There,has,been,an,awakening')应返回'There has been an awakening'

assert(
  sentensify('There,has,been,an,awakening') === 'There has been an awakening'
);

--solutions--