Created
October 30, 2016 04:37
-
-
Save danielborowski/b47b6899438f2b5165d24a07eb6315d0 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