Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

07-HashCollisionLinearProbing.js #13

Closed
chung2014 opened this issue May 29, 2016 · 1 comment
Closed

07-HashCollisionLinearProbing.js #13

chung2014 opened this issue May 29, 2016 · 1 comment

Comments

@chung2014
Copy link

In line 49, you are checking for a position that contains an element, so I guess you would like to break the while loop if there is no value for that position
so

while (table[index] === undefined || table[index].key !== key)

should be

while (table[index] !== undefined || table[index].key !== key)
@dear-lizhihua
Copy link

dear-lizhihua commented Aug 6, 2016

hashLinearProbing.remove('Jamie');
console.log(hashLinearProbing.get('Jamie'));

table[index].key will error

so

while (table[index] === undefined || table[index].key !== key){
    index++;
}
if (table[index].key === key) {
    return table[index].value;
}

maybe should be

while (table[index] !== undefined && (table[index] && table[index].key !== key)){
  index++;
}
if ((table[index] && table[index].key === key)) {
  return table[index].value;
}

@loiane loiane closed this as completed in 7868536 Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants