...
), Array.prototype.sort()
and String.prototype.localeCompare()
to sort the characters in str
.String.prototype.join('')
.const sortCharactersInString = str => [...str].sort((a, b) => a.localeCompare(b)).join('');
sortCharactersInString('cabbage'); // 'aabbceg'
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️