stordahl commented on issue #54:
URL: https://github.com/apache/arrow-js/issues/54#issuecomment-3491678485
Noting this is still an issue and wanted to share my patch solution for
anyone that finds this issue in the future. I'll open a PR if a maintainer
thinks the solution is appropriate.
```typescript
/**
* Dynamically compile the null values into an `isValid()` function.
* This implementation uses a Set for O(1) lookup while maintaining
performance.
*
* @example
* const isValid = createIsValidFunction([null, 'N/A', NaN]);
* isValid(null); // false
* isValid('N/A'); // false
* isValid(NaN); // false
* isValid('valid'); // true
*
* @ignore
* @param nullValues
*/
function createIsValidFunction(nullValues) {
if (!nullValues || nullValues.length <= 0) {
return function isValid(value) { return true; };
}
// Separate NaN from other null values since NaN !== NaN
const hasNaN = nullValues.some((x) => x !== x);
const noNaNs = nullValues.filter((x) => x === x);
// Use a Set for O(1) lookup of non-NaN null values
const nullSet = new Set(noNaNs);
return function isValid(x) {
if (hasNaN && x !== x) return false;
return !nullSet.has(x);
};
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]