2.1 KiB
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7daa367417b2b2512b6c | Transformar um array em uma string usando o método join | 1 | 18221 | combine-an-array-into-a-string-using-the-join-method |
--description--
O método join
é usado para juntar os elementos de um array, resultando em uma string. Ele recebe um delimitador como argumento, que é usado para conectar os elementos na string.
Exemplo:
var arr = ["Hello", "World"];
var str = arr.join(" ");
O valor de str
é Hello World
.
--instructions--
Use o método join
(entre outros) dentro da função sentensify
para criar uma frase a partir das palavras da string str
. A função deve retornar uma string. Por exemplo, I-like-Star-Wars
deve ser convertido para I like Star Wars
. Não use o método replace
neste desafio.
--hints--
Você deve usar o método join
.
assert(code.match(/\.join/g));
Você não deve usar o método replace
.
assert(!code.match(/\.?[\s\S]*?replace/g));
sentensify("May-the-force-be-with-you")
deve retornar uma string.
assert(typeof sentensify('May-the-force-be-with-you') === 'string');
sentensify("May-the-force-be-with-you")
deve retornar a string 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")
deve retornar a string 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")
deve retornar a string There has been an awakening
.
assert(
sentensify('There,has,been,an,awakening') === 'There has been an awakening'
);
--seed--
--seed-contents--
function sentensify(str) {
// Only change code below this line
// Only change code above this line
}
sentensify("May-the-force-be-with-you");
--solutions--
function sentensify(str) {
// Only change code below this line
return str.split(/\W/).join(' ');
// Only change code above this line
}