wordEnds: the letters around each word
For each appearance of word in str, collect the character just before it and the character just after it (when they exist). A character can be used twice if it sits between two words. Step through wordEnds: instead of checking every index, it uses indexOf(word, from) to jump straight to the next appearance.