* Check if a value is in an array, with optional pre-built Set for optimization. * The primitiveSet is cached in InField during extraction and reused for all lookups.
( array: Array<any>, value: any, primitiveSet: Set<any> | null, arrayIsAllPrimitives?: boolean, )
| 1140 | * The primitiveSet is cached in InField during extraction and reused for all lookups. |
| 1141 | */ |
| 1142 | function arrayIncludesWithSet( |
| 1143 | array: Array<any>, |
| 1144 | value: any, |
| 1145 | primitiveSet: Set<any> | null, |
| 1146 | arrayIsAllPrimitives?: boolean, |
| 1147 | ): boolean { |
| 1148 | // Fast path: use pre-built Set for O(1) lookup |
| 1149 | if (primitiveSet) { |
| 1150 | // Skip isPrimitive check if we know the value must be primitive for a match |
| 1151 | // (if array is all primitives, only primitives can match) |
| 1152 | if (arrayIsAllPrimitives || isPrimitive(value)) { |
| 1153 | return primitiveSet.has(value) |
| 1154 | } |
| 1155 | return false // Non-primitive can't be in primitive-only set |
| 1156 | } |
| 1157 | |
| 1158 | // Fallback: use areValuesEqual for Dates and objects |
| 1159 | return array.some((v) => areValuesEqual(v, value)) |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * Get the maximum of two values, handling both numbers and Dates |
no test coverage detected