The following line of code will equal the number of array values present when the selected text is split by a space.
Code:
window.getSelection().toString().split(/\s/).length;
window.getSelection() returns a selection object which can be converted into a string containing the exact characters selected. Afterwards, you need to apply a simple split by space function (using split()) and get the length of the array returned.
https://developer.mozilla.org/en-US/...w.getSelection
https://developer.mozilla.org/en-US/...s/String/split
Bookmarks