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

40 lines
928 B
Markdown
Raw Normal View History

---
id: a202eed8fc186c8434cb6d61
title: 反转字符串
challengeType: 5
videoUrl: ''
---
# --description--
反转提供的字符串。您可能需要先将字符串转换为数组,然后才能将其反转。您的结果必须是字符串。如果卡住,请记得使用[Read-Search-Ask](https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514) 。编写自己的代码。
# --hints--
`reverseString("hello")`应该返回一个字符串。
```js
assert(typeof reverseString('hello') === 'string');
```
`reverseString("hello")`应该变成`"olleh"` 。
```js
assert(reverseString('hello') === 'olleh');
```
`reverseString("Howdy")`应该变成`"ydwoH"` 。
```js
assert(reverseString('Howdy') === 'ydwoH');
```
`reverseString("Greetings from Earth")`应返回`"htraE morf sgniteerG"` 。
```js
assert(reverseString('Greetings from Earth') === 'htraE morf sgniteerG');
```
# --solutions--