INNER CODE UNIT · TypeScript
firstMatchIndex
akirarika/milkio · packages/cookbook/src/index.ts:140
let firstMatchIndex = -1;
let inputIndex = 0;
for (let i = 0; i < target.length; i++) {
if (target[i] === input[inputIndex]) {
if (firstMatchIndex === -1) firstMatchIndex = i;
currentContiguous++;
inputIndex++;
maxContiguous = Math.max(maxContiguous, currentContiguous);
} else {
currentContiguous = 0;
}
}
return { maxContiguous, firstMatchIndex };
};
const selected = await (async () => {
const { controller, timeoutId } = createPromptAbortController();