Sort the characters of a string in the alphabetical order
JavaScript version
const sort = (str) =>
str
.split('')
.sort((a, b) => a.localeCompare(b))
.join('');
TypeScript version
const sort = (str: string): string =>
str
.split('')
.sort((a, b) => a.localeCompare(b))
.join('');
Examples
sort('hello world'); // dehllloorw