Here is a small and simple JavaScript function to sort an array by the number of words in each array item. Of course the assumption here is the array is an array of strings/text.
You can sort the array from the least number of words to most [bAscending = true] or most number of words to least [bAscending = false]
Here is an example of how to use the function: