-
Notifications
You must be signed in to change notification settings - Fork 37
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
Implement doubly linked list #10
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Попробуй прогнать код через линтер eslint, его конфиги я присылал
JavaScript/doubly_classbased.js
Outdated
*/ | ||
let current = this.head; | ||
while (current) { | ||
if (typeof(current.data) === LinkedList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeof отдает же строку
JavaScript/doubly_classbased.js
Outdated
if (this.length === 0) { | ||
this.head = new Node(data); | ||
this.tail = this.head; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
чего перенос строки?
JavaScript/doubly_classbased.js
Outdated
|
||
pop() { | ||
if (!this.tail) { | ||
throw Error('Pop from empty list'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если только можно не делать throw, его делать не нужно
JavaScript/doubly_classbased.js
Outdated
|
||
findFirst(data) { | ||
let current = this.head; | ||
while (current !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while (current)
JavaScript/doubly_classbased.js
Outdated
let current = this.head; | ||
let nodes = []; | ||
while (current !== null) { | ||
if (current.data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (current.data.toString().match(regex)) {
nodes.push(current);
}
или
const matched = current.data.toString().match(regex);
if (matched) nodes.push(current);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не принято сносить каждый метод на новую строку? Пару раз видел примеры кода с таким стилем.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Делать это внутри if-условия не хорошо, а в присваивании можно, если в строку не влазит или для концептуальной красоты.
JavaScript/doubly_classbased.js
Outdated
throw Error('Pop from empty list'); | ||
} | ||
if (!this.tail) | ||
return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Просто return
JavaScript/doubly_classbased.js
Outdated
if (this.head) { | ||
return this.head.toString(); | ||
} | ||
return 'Empty list'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Возвращать сообщение об ошибке в строке плохо.
toString() {
if (!this.head) return;
return this.head.toString();
}
JavaScript/doubly_classbased.js
Outdated
} | ||
|
||
isEmpty() { | ||
return Boolean(this.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return !!this.length;
JavaScript/doubly_classbased.js
Outdated
} | ||
|
||
pop() { | ||
if (!this.tail) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}
No description provided.