-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Labels
Description
Hello all,
I recently noticed the includes function in the util folder, which was originally added in 2018, as some sort of polyfill for the Array.prototype.includes() method:
9457642 - "Created includes function for array to cater older browsers"
I see a few issues with this in the meantime:
- Please correct me if I am wrong, as I am not Babel expert, but doesn't "Babel" take care of that anyways?
- this function is currently only used in isDecimal exclusively (the other 2 functions in the commit above in the meantime where moved to using "Sets" instead of Arrays, so this
includesfunction is not applicable to these anymore) - the
Array.prototype.some()method is a lot slower thanArray.prototype.includes(): I ran a few local benchmarks with benchmark package, and the nativeArray.prototype.includes()method was always 2-4x times faster
node .\benchmark.js
with native `Array.prototype.includes()` x 843,902,658 ops/sec ±0.18% (91 runs sampled)
with current `Array.prototype.some()` polyfill type x 147,008,135 ops/sec ±0.10% (95 runs sampled)
Fastest is with native `Array.prototype.includes()`
So question here is:
Am I wrong about Babel?
If not: Are there any reason to still keep this includes function?
That util function is not exported, so there also shouldn't be any backwards compatibility issues, that we need to keep in mind.
What are your thoughts?
Happy to take care about the PR for this then
Kind regards,
Pano