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.

29 lines (21 loc) 782 B
import { BLANK } from '@scrabble-solver/constants'; import { type Tile } from '@scrabble-solver/types'; import { type Rack } from '@/types'; interface CharacterTilePair { character: string | null; tile: Tile | null; } export const zipCharactersAndTiles = (characters: Rack, tiles: Tile[]): CharacterTilePair[] => { let remainingTiles = [...tiles]; return characters.map((character) => { const index = remainingTiles.findIndex((tile) => character === BLANK ? tile.isBlank : character === tile.character, ); if (index >= 0) { const tile = remainingTiles[index]; remainingTiles = [...remainingTiles.slice(0, index), ...remainingTiles.slice(index + 1)]; return { character, tile }; } return { character, tile: null }; }); };