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

Lab completed. All tests passed. #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Wilsantos1975
Copy link

Lab completed

Comment on lines +21 to +29
size() {
let count = 0;
let currentNode = this.head;
while (currentNode) {
count++;
currentNode = currentNode.next;
}
return count;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think of a way to have this function run in O(1) instead of O(n)?

Comment on lines +96 to +100
if (this.head === null) {
return true;
} else {
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.head === null) {
return true;
} else {
return false;
}
!this.head

Comment on lines +149 to +161
containsDuplicates() {
let currentNode = this.head;
let array = [];
while (currentNode) {
if (array.includes(currentNode.data)) {
return true;
}
array.push(currentNode.data);
currentNode = currentNode.next;
}
return false;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think of a shorter, cleaner and more efficient way to write this function using this.toArray and a set?

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

Successfully merging this pull request may close these issues.

2 participants