You have infinite loop condition in your setWordsOnField
function.
During initial words placement you can place words in way they overlap each other (one of the examples is [алтей, граб, астра] [[0, 3], [2, 3], [2, 5]]
, so граб
overlaps астра
by one symbol. In second loop you check that there is no words crossing. Since there is words crossing, wordCrossingCheck(words, wordsPositions, way)
will always return true and it will be infinite cycle.