Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning JavaScript Data Structures and Algorithms
  • Table Of Contents Toc
Learning JavaScript Data Structures and Algorithms

Learning JavaScript Data Structures and Algorithms - Fourth Edition

By : Loiane Groner, Aris Markogiannakis, Daniel Ostrovsky
close
close
Learning JavaScript Data Structures and Algorithms

Learning JavaScript Data Structures and Algorithms

By: Loiane Groner, Aris Markogiannakis, Daniel Ostrovsky

Overview of this book

Data structures and algorithms are foundational topics for software developers. This easy-to-follow book from experienced developer and trainer Loiane Groner will help you to fill in the gaps in your knowledge – whether you’re a self-taught developer, you’re preparing for technical interviews, or you just want to write better code and improve your problem-solving skills. This fourth edition covers essential data structures, algorithms, and their usage in the context of JavaScript. You’ll follow examples in both JavaScript and TypeScript, in line with the latest standards and best practices, learning how to do complexity analysis along the way. New to this edition are LeetCode and HackerRank exercises at the end of each chapter, which you'll be guided through solving. You’ll also find brand-new chapters on the tries data structure, and string and math algorithms. By the end of the book, you will know how to develop programs using the best data structures and algorithms for the job.
Table of Contents (9 chapters)
close
close
Lock Free Chapter
1
Learning JavaScript Data Structures and Algorithms, Fourth Edition: Enhance your problem-solving skills in JavaScript and TypeScript

Creating the HashTable class

Our hash table implementation will be located in the src/08-dictionary-hash/hash-table.js file. We begin by defining the HashTable class:

class HashTable {
  #table = [];
}

This initial step simply initializes the private #table array, which will serve as the underlying storage for our key-value pairs.

Next, we will equip our HashTable class with three essential methods:

  1. put(key, value): this method either adds a new key-value pair to the hash table or updates the value associated with an existing key.
  2. remove(key): this method removes the value and its corresponding key from the hash table based on the provided key.
  3. get(key): this method retrieves the value associated with a specific key from the hash table.

To enable the functionality of these methods, we also need to create a crucial component: the hash function. This function will play a vital role in determining the storage location of each key-value pair within the hash table, making it a cornerstone...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon