javascript hot to sort letters 1

javascript hot to sort letters

const sort = str => str.split('').sort((a, b) => a.localeCompare(b)).join('');

// Example:
sort('eat'); 
// Output:
// 'aet'

Here is what the above code is Doing:
1. We split the string into an array of characters.
2. We sort the array using the localeCompare() method.
3. We join the array back into a string.

Similar Posts