Javasript Code Function to Sort an Array by Word Count

Here is a small and simple JavaScript function to sort an array by the number of words in each array item. You can sort from least number of words to most or most number of words to least

Home Short:

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:

S
H
A
R
E