Stop at the
first match.
Trace a TypeScript loop one cell at a time. Pud proves it returns the first matching index, or −1n if the target is missing.
linear-search.ts
let index = 0n;for (const value of values) {if (value === target) return index;index += 1n;}return -1n;
values[]
[0]4
[1]8
[2]7
[3]7
[4]3