* Neighbours in their own order, not in the order they arrived. * * The recipe already sorts them, and this sorts them again by the same key. Not * redundant: a compiler whose output depended on the order a caller happened to * assemble a packet in would be one refactor away from producing two d
(entries: readonly NeighbourFact[])
| 327 | * set. Idempotent by construction, since the key is the recipe's key. |
| 328 | */ |
| 329 | function orderedNeighbours(entries: readonly NeighbourFact[]): NeighbourFact[] { |
| 330 | return [...entries].sort((a, b) => { |
| 331 | if (a.hop !== b.hop) { |
| 332 | return a.hop - b.hop; |
| 333 | } |
| 334 | if (a.direction !== b.direction) { |
| 335 | return a.direction < b.direction ? -1 : 1; |
| 336 | } |
| 337 | const left = a.qualifiedName ?? a.name; |
| 338 | const right = b.qualifiedName ?? b.name; |
| 339 | if (left === right) { |
| 340 | return 0; |
| 341 | } |
| 342 | return left < right ? -1 : 1; |
| 343 | }); |
| 344 | } |
| 345 | |
| 346 | function neighbourDrafts(packet: FactPacket, rank: (kind: CardKind) => number): Draft[] { |
| 347 | const subjectName = packet.subject?.name ?? 'the subject'; |