* What every arm of a switch is deciding on: the longest start they share, cut * at a word. '' when they share nothing — then the head says nothing and each * arm says its own condition, which is never wrong.
(arms: readonly string[])
| 397 | * arm says its own condition, which is never wrong. |
| 398 | */ |
| 399 | function subjectOf(arms: readonly string[]): string { |
| 400 | if (arms.length < 2) return ''; |
| 401 | let common = arms[0]!; |
| 402 | for (const arm of arms.slice(1)) { |
| 403 | let i = 0; |
| 404 | while (i < common.length && i < arm.length && common[i] === arm[i]) i++; |
| 405 | common = common.slice(0, i); |
| 406 | } |
| 407 | return /^[\w$.?[\]'"]+/.exec(common.trim())?.[0] ?? ''; |
| 408 | } |
| 409 | |
| 410 | /** Whether the last thing a block does is answer the request. */ |
| 411 | function repliesLast(input: ProgramInput, block: WireBlock): boolean { |