Merge pull request #231 from wojtekmaj/change/reverseString-no-spread
reverseString: Replace spread operator with split() for compatibility
This commit is contained in:
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
Reverses a string.
|
Reverses a string.
|
||||||
|
|
||||||
Use array destructuring and `Array.reverse()` to reverse the order of the characters in the string.
|
Use `split('')` and `Array.reverse()` to reverse the order of the characters in the string.
|
||||||
Combine characters to get a string using `join('')`.
|
Combine characters to get a string using `join('')`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const reverseString = str => [...str].reverse().join('');
|
const reverseString = str => str.split('').reverse().join('');
|
||||||
// reverseString('foobar') -> 'raboof'
|
// reverseString('foobar') -> 'raboof'
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user