Let’s say we need to convert the string into alphabetical order –
geeksforgeeks -> eeeefggkkorss
Approach: The task is to create a function that takes a string and returns the alphabetical order of that string.
Step 2:Sort the array of characters in alphabetical order with the help of sort() function
Step 3:Join the characters into one string with the help of join() method
If we try to put whitespace in between our passing string it will result in putting that white space in starting of the resultant string. Like in the above example string has 1 white space and in the resultant string it is useless, so to get rid of that we can use white space regular expression i.e. \s+ for selecting white spaces and replacing it with an empty string.