Created
October 30, 2016 04:37
-
-
Save danielborowski/208911f544f98ce6588de7afb48d9557 to your computer and use it in GitHub Desktop.
This file contains 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
// assume we have an array called "list_of_items" | |
// that contains the names of over 1 million items | |
// first we'll create a new hash table that will allow | |
// us to later search for elements very quickly | |
let hashtable = {}; | |
for (let item of list_of_items) { | |
if (!hashtable[item]) { | |
hashtable[item] = true; | |
} | |
} | |
// now searching is much faster | |
console.log(hashtable['The Great Gatsby']); // => will return true or undefined | |
console.log(hashtable['Kindle Fire']); | |
console.log(hashtable['Amazon Echo']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment