import {Letter} from "word_grid"; import {LocationType, PlayableLetterData} from "./elements"; export function addNTimes(array: T[], toAdd: T, times: number) { for (let i=0; i(); for (let i = 0; i { return x !== undefined && x !== null; }).forEach((x) => { if (x.location === LocationType.TRAY) { freeSpots[x.index] = null; } }); const firstNotNull = (): number => { for (let i of freeSpots) { if (i !== null) { freeSpots[i] = null; return i; } } return null; } return newer.map((ld, i) => { if (ld !== undefined) { if (existing[i] !== undefined && existing[i] !== null && existing[i].location === LocationType.TRAY) { ld["index"] = existing[i].index; } else { ld["index"] = firstNotNull(); } ld["location"] = LocationType.TRAY; } return ld as PlayableLetterData; }); }