Created
May 16, 2019 14:46
-
-
Save hergaiety/ffdd1e0070f527bb53f00d813c92278f to your computer and use it in GitHub Desktop.
Avoiding Nested Loops with `new Map()`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myHugeArray = [...Array(10000).keys()].map(id => { return {id}; }); | |
let listIWant = [1010, 2020, 3030, 4040, 5050, 6060, 7070, 8080, 9090]; | |
// INSTEAD OF: | |
myHugeArray.filter(obj => listIWant.includes(obj.id)); | |
// TRY: | |
let mapIWant = new Map(); | |
listIWant.forEach(id => mapIWant.set(id)); | |
myHugeArray.filter(obj => mapIWant.has(obj.id)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment