Files
30-seconds-of-code/snippets/sortCharactersInString.md
2017-12-25 14:49:52 +01:00

15 lines
354 B
Markdown

### sortCharactersInString
Alphabetically sorts the characters in a string.
Split the string using `split('')`, `Array.sort()` utilizing `localeCompare()`, recombine using `join('')`.
```js
const sortCharactersInString = str =>
str.split('').sort((a, b) => a.localeCompare(b)).join('');
```
```js
sortCharactersInString('cabbage') -> 'aabbceg'
```