Files
30-seconds-of-code/snippets/sortCharactersInString.md
Angelos Chalaris 97c250bcfb Updated examples
2017-12-27 16:35:25 +02: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'
```