Word Frequency Sorter
Given a string containing a series of words separated by spaces, write a function that returns a new string where the words are sorted based on their frequency of occurrence in descending order. In case two words have the same frequency, sort the words alphabetically.
[ "word word repeat repeat repeat" ]
Explanation. The word 'repeat' occurs 3 times and the word 'word' occurs 2 times.
[ "this is is a test test test string" ]
Explanation. 'test' appears 3 times, 'is' appears 2 times, and the other words appear once, sorted alphabetically.
[ "single" ]
Explanation. The string contains only one word, so it is output as is.
[ "word another word" ]
Explanation. 'word' appears twice and 'another' appears once.
Follow-up: How would your solution change if punctuations, numbers, and uppercase letters were included in the input?
The input string will include only lowercase letters and space characters. It is guaranteed to contain at least one word.