Skip to content

Instantly share code, notes, and snippets.

@danielborowski
Created October 30, 2016 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielborowski/208911f544f98ce6588de7afb48d9557 to your computer and use it in GitHub Desktop.
Save danielborowski/208911f544f98ce6588de7afb48d9557 to your computer and use it in GitHub Desktop.
// 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