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

PR 7: Node class #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

PR 7: Node class #7

wants to merge 1 commit into from

Conversation

CheezItMan
Copy link

No description provided.

Copy link

@anakp07 anakp07 left a comment

Choose a reason for hiding this comment

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

This looks good!

Comment on lines +24 to +31
printList() {
let current = this;

while (current != null) {
console.log(current.value);
current = current.getNext();
}
}

Choose a reason for hiding this comment

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

It may be better to convert this into a toString() method and have console.log() called on Node outside of the class in case of any unwanted print messages.

Copy link

Choose a reason for hiding this comment

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

Consider: Perhaps a function to printList should probably live in the list class (not in the node).

Comment on lines +3 to +6
constructor(value, next) {
this.value = value;
this.next = next;
}

Choose a reason for hiding this comment

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

Assuming this is for a linked list, it may help to add validations to ensure next is also a Node -- Otherwise, some comments about what each field represents could help clarify the constructor's post conditions.

Copy link

Choose a reason for hiding this comment

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

Also, can next node be be given default null value to account for if the next value is not given (end of list)?

Copy link

Choose a reason for hiding this comment

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

Don't know if this is possible in js, maybe will be taken care of in the linked list class

printList() {
let current = this;

while (current != null) {
Copy link

@ghostfruitleaf ghostfruitleaf Mar 12, 2021

Choose a reason for hiding this comment

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

Suggested change
while (current != null) {
while (current) {

(nit) null is falsy in Javascript, which allows the while loop to check through while(current).

Copy link

@ghostfruitleaf ghostfruitleaf left a comment

Choose a reason for hiding this comment

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

Looks great :D -- added a few suggestions as well!

(Also the code doesn't need changing, I don't think? -- just trying to get practice in with comments...)

Comment on lines +12 to +14
setNext(next) {
this.next = next;
}
Copy link

Choose a reason for hiding this comment

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

I believe this is already set in the constructor, therefor not necessary.

Copy link

Choose a reason for hiding this comment

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

Thank you for the <3

Comment on lines +20 to +22
setValue(value) {
this.value = value;
}
Copy link

Choose a reason for hiding this comment

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

This is also already set in the constructor. So not necessary?

Copy link

Choose a reason for hiding this comment

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

Thank you for the confirmation, I was starting to doubt myself lol

Choose a reason for hiding this comment

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

I think you can still have a set method if you only want to change one field, but I also don't think it's recommended either way?

Copy link

@r-spiel r-spiel left a comment

Choose a reason for hiding this comment

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

Please see comments.

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.

4 participants