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

2.0 KiB

id title localeTitle isRequired challengeType
a202eed8fc186c8434cb6d61 Reverse a String Revertir una cadena true 5

Description

Invertir la cadena proporcionada. Es posible que deba convertir la cadena en una matriz antes de poder revertirla. Su resultado debe ser una cadena. Recuerda usar Read-Search-Ask si te atascas. Escribe tu propio código.

Instructions

Tests

tests:
  - text: <code>reverseString(&quot;hello&quot;)</code> debe devolver una cadena.
    testString: 'assert(typeof reverseString("hello") === "string", "<code>reverseString("hello")</code> should return a string.");'
  - text: <code>reverseString(&quot;hello&quot;)</code> debe convertirse en <code>&quot;olleh&quot;</code> .
    testString: 'assert(reverseString("hello") === "olleh", "<code>reverseString("hello")</code> should become <code>"olleh"</code>.");'
  - text: <code>reverseString(&quot;Howdy&quot;)</code> debe convertirse en <code>&quot;ydwoH&quot;</code> .
    testString: 'assert(reverseString("Howdy") === "ydwoH", "<code>reverseString("Howdy")</code> should become <code>"ydwoH"</code>.");'
  - text: <code>reverseString(&quot;Greetings from Earth&quot;)</code> debe devolver <code>&quot;htraE morf sgniteerG&quot;</code> .
    testString: 'assert(reverseString("Greetings from Earth") === "htraE morf sgniteerG", "<code>reverseString("Greetings from Earth")</code> should return <code>"htraE morf sgniteerG"</code>.");'

Challenge Seed

function reverseString(str) {
  return str;
}

reverseString("hello");

Solution

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

reverseString("hello");