2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: a202eed8fc186c8434cb6d61
|
2021-02-06 04:42:36 +00:00
|
|
|
title: Reverse a String
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 5
|
2021-01-12 08:18:51 -08:00
|
|
|
forumTopicId: 16043
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: reverse-a-string
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
Reverse the provided string.
|
2021-01-12 08:18:51 -08:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
You may need to turn the string into an array before you can reverse it.
|
2021-01-12 08:18:51 -08:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
Your result must be a string.
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`reverseString("hello")` should return a string.
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(typeof reverseString('hello') === 'string');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`reverseString("hello")` should become `"olleh"`.
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert(reverseString('hello') === 'olleh');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`reverseString("Howdy")` should become `"ydwoH"`.
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(reverseString('Howdy') === 'ydwoH');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
`reverseString("Greetings from Earth")` should return `"htraE morf sgniteerG"`.
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert(reverseString('Greetings from Earth') === 'htraE morf sgniteerG');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function reverseString(str) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
reverseString("hello");
|
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
```js
|
|
|
|
function reverseString(str) {
|
|
|
|
return str.split('').reverse().join('');
|
|
|
|
}
|
|
|
|
|
|
|
|
reverseString("hello");
|
|
|
|
```
|