Small code errors for the LinkedList and HashTable data structures

Open
#1,033 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
javascript
Domain
data

Research direction

Search the LinkedList delete() method and the HashTable constructor in the JavaScript source. Check the surrounding implementations and existing tests before making the two corrections described in the issue; done means both data structures use the intended statements without changing other behavior.

Written by the indexing model from the issue text.

Description

Hello!

As I went through the code for these data structures, I noticed two small errors:

  1. inside the delete() method of the LinkedList data structure, there is a line of code that says: while (this.head && this.compare.equal(this.head.value, value)). However, instead of a while it should be an if statement.

  2. inside the constructor() of the HashTable data structure, we initialize an array in the following way: this.buckets = Array(hashTableSize).fill(null).map(() => new LinkedList());. However, the Array() constructor should have the new keyword in front of it.

If you guys feel that these are important fixes to you and if you allow me to help, I would be more than glad to contribute by creating a pull request with the changes made.

Dominant language
JavaScript
Stars
197k
Forks
31k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from trekhleb/javascript-algorithms

All issues in trekhleb/javascript-algorithms

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.