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

2.2 KiB

id title challengeType forumTopicId dashedName
587d7daa367417b2b2512b6c Combinare un array in una stringa usando il metodo join 1 18221 combine-an-array-into-a-string-using-the-join-method

--description--

Il metodo join viene utilizzato per unire gli elementi di un array per creare una stringa. Prende un argomento che sarà il delimitatore che viene utilizzato per separare gli elementi dell'array nella stringa.

Ecco un esempio:

const arr = ["Hello", "World"];
const str = arr.join(" ");

str conterrà la stringa Hello World.

--instructions--

Usa il metodo join (tra gli altri) all'interno della funzione sentensify per creare una frase a partire dalle parole contenute nella stringa str. La funzione dovrebbe restituire una stringa. Ad esempio, I-like-Star-Wars sarebbe stato convertito in I like Star Wars. Per questa sfida, non utilizzare il metodo replace.

--hints--

Il tuo codice dovrebbe utilizzare il metodo join.

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

Il tuo codice non dovrebbe usare il metodo replace.

assert(!code.match(/\.?[\s\S]*?replace/g));

sentensify("May-the-force-be-with-you") dovrebbe restituire una stringa.

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

sentensify("May-the-force-be-with-you") dovrebbe restituire la stringa 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") dovrebbe restituire la stringa 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") dovrebbe restituire la stringa 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) {
  return str.split(/\W/).join(' ');
}