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