src/lib/wordfind.js
function (word, puzzle, x, y, fnGetSquare) {
            var overlap = 0;
            // traverse the squares to determine if the word fits
            for (var i = 0, len = word.length; i < len; i++) {
                var next = fnGetSquare(x, y, i), square = puzzle[next.y][next.x];
                // if the puzzle square already contains the letter we
                // are looking for, then count it as an overlap square
                if (square === word[i]) {
                    overlap++;
                }
                else if (square !== '') {
                    return -1;
                }
            }
            // if the entire word is overlapping, skip it to ensure words aren't
            // hidden in other words
            return overlap;
        }
function (word, puzzle, x, y, fnGetSquare) {
            var overlap = 0;
            // traverse the squares to determine if the word fits
            for (var i = 0, len = word.length; i < len; i++) {
                var next = fnGetSquare(x, y, i), square = puzzle[next.y][next.x];
                // if the puzzle square already contains the letter we
                // are looking for, then count it as an overlap square
                if (square === word[i]) {
                    overlap++;
                }
                else if (square !== '') {
                    return -1;
                }
            }
            // if the entire word is overlapping, skip it to ensure words aren't
            // hidden in other words
            return overlap;
        }
function ( word , puzzle , x , y , fnGetSquare ) { var overlap = 0 ; // traverse the squares to determine if the word fits for ( var i = 0 , len = word . length ; i < len ; i ++ ) { var next = fnGetSquare ( x , y , i ) , square = puzzle [ next . y ] [ next . x ] ; // if the puzzle square already contains the letter we // are looking for, then count it as an overlap square if ( square === word [ i ] ) { overlap ++ ; } else if ( square !== '' ) { return - 1 ; } } // if the entire word is overlapping, skip it to ensure words aren't // hidden in other words return overlap ; }
Determines whether or not a particular word fits in a particular
orientation within the puzzle.

Returns the number of letters overlapped with existing words if the word
fits in the specified position, -1 if the word does not fit.

@param {String} word: The word to fit into the puzzle.
@param {[[String]]} puzzle: The current state of the puzzle
@param {int} x: The x position to check
@param {int} y: The y position to check
@param {function} fnGetSquare: Function that returns the next square
Determines whether or not a particular word fits in a particular orientation within the puzzle .