Update Posts “using-js-sets-to-find-elements”
This commit is contained in:
parent
e40175d8d1
commit
dacade6fcc
1 changed files with 5 additions and 1 deletions
|
@ -26,7 +26,11 @@ description: >-
|
||||||
|
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
Functionally for one check, this is identical to checking the `.indexOf()` or `.includes()` of an Array. However, in cases where you're filtering a large array down to match a list of ID's, for example, the nested looping can result in a performance hit. Traditionally hash tables were used for speeding up this search, but with ES2015 we can now leverage Sets which are easier to read and still result in a single loop that's equal to the length of the Array and no more. (Can be further optimized by ending when running out of needles)
|
Functionally for one check, this is identical to checking the `.indexOf()` or `.includes()` of an Array. However, in cases where you're filtering a large array down to match a list of ID's, for example, the nested looping can result in a performance hit.
|
||||||
|
|
||||||
|
Traditionally hash tables were used for speeding up this search, but with ES2015 we can now leverage Sets which are easier to read and still result in a single loop that's equal to the length of the Array and no more.
|
||||||
|
|
||||||
|
(Can be further optimized by ending when running out of needles)
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Example Data
|
// Example Data
|
||||||
|
|
Loading…
Add table
Reference in a new issue