4 ms·
I don’t think the root logic it ultimately depends on is obvious: https://github.com/jonschlinkert/is-number/blob/master/index.js https://github.com/jonschlinke
by pacifika 2y ago
I don’t think the root logic it ultimately depends on is obvious: https://github.com/jonschlinkert/is-number/blob/master/index.js https://github.com/jonschlinkert/is-number/blob/master/index...
And so this is a perfect abstraction to make something non- obvious obvious.
The real question is why this shouldn’t be part of the interpreter?
Yes the dependency on isOdd is needless, but is a red herring.
Most commenters here didn’t look deep enough, sadly.
- aidos 2y agoHmmm, that's not what I'm seeing when all this is put together. isOdd coerces to a number using Math.abs, so the string checks in isNumber don't apply. function isOdd(value) { const n = Math.abs(value); if (!isNumber(n)) { throw new TypeError('expected a number'); } if (!Number.isInteger(n)) { throw new Error('expected an integer'); } if (!Number.isSafeInteger(n)) { throw new Error('value exceeds maximum safe integer'); } return (n % 2) === 1; } function isNumber(num) { if (typeof num === 'number') { return num - num === 0; } if (typeof num === 'string' && num.trim() !== '') { return Number.isFinite ? Number.isFinite(+num) : isFinite(+num); } return false; }