UNPKG

scrabble-solver

Version:

Scrabble Solver 2 - Free, open-source, cross-platform, multi-language analysis tool for Scrabble, Scrabble Duel, Super Scrabble, Letter League, Crossplay, Literaki, and Kelimelik. Quickly find the top-scoring words using the given board and tiles.

17 lines (13 loc) 576 B
export const findFirstWordIndex = (lines: string[], locale: string): number => { const firstWordIndex = lines.findIndex((line, index) => { const nextLine = line[index + 1] || ''; const isNextLineInOrder = line.localeCompare(nextLine, locale) > 0; const hasWhitespace = Boolean(line.match(/\s/)); const isEmpty = line.trim().length === 0; return !isEmpty && !hasWhitespace && isNextLineInOrder; }); if (typeof firstWordIndex === 'undefined') { throw new Error('Cannot find index of the first word in the file'); } return firstWordIndex; };