freeCodeCamp/curriculum/challenges/italian/02-javascript-algorithms-an.../basic-algorithm-scripting/reverse-a-string.md

1.1 KiB

id title challengeType forumTopicId dashedName
a202eed8fc186c8434cb6d61 Invertire una stringa 5 16043 reverse-a-string

--description--

Inverti la stringa fornita.

Potrebbe essere necessario trasformare la stringa in un array prima di poterla invertire.

Il tuo risultato deve essere una stringa.

--hints--

reverseString("hello") dovrebbe restituire una stringa.

assert(typeof reverseString('hello') === 'string');

reverseString("hello") dovrebbe restituire la stringa olleh.

assert(reverseString('hello') === 'olleh');

reverseString("Howdy") dovrebbe restituire la stringa ydwoH.

assert(reverseString('Howdy') === 'ydwoH');

reverseString("Greetings from Earth") dovrebbe restituire la stringa htraE morf sgniteerG.

assert(reverseString('Greetings from Earth') === 'htraE morf sgniteerG');

--seed--

--seed-contents--

function reverseString(str) {
  return str;
}

reverseString("hello");

--solutions--

function reverseString(str) {
  return str.split('').reverse().join('');
}

reverseString("hello");