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

Implement doubly linked list #10

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

Implement doubly linked list #10

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 7, 2017

No description provided.

Copy link
Member

@tshemsedinov tshemsedinov left a comment

Choose a reason for hiding this comment

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

Попробуй прогнать код через линтер eslint, его конфиги я присылал

*/
let current = this.head;
while (current) {
if (typeof(current.data) === LinkedList) {
Copy link
Member

Choose a reason for hiding this comment

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

typeof отдает же строку

if (this.length === 0) {
this.head = new Node(data);
this.tail = this.head;
}
Copy link
Member

Choose a reason for hiding this comment

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

чего перенос строки?


pop() {
if (!this.tail) {
throw Error('Pop from empty list');
Copy link
Member

Choose a reason for hiding this comment

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

Если только можно не делать throw, его делать не нужно


findFirst(data) {
let current = this.head;
while (current !== null) {
Copy link
Member

Choose a reason for hiding this comment

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

while (current)

let current = this.head;
let nodes = [];
while (current !== null) {
if (current.data
Copy link
Member

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);

Copy link
Author

Choose a reason for hiding this comment

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

Не принято сносить каждый метод на новую строку? Пару раз видел примеры кода с таким стилем.

Copy link
Member

Choose a reason for hiding this comment

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

Делать это внутри if-условия не хорошо, а в присваивании можно, если в строку не влазит или для концептуальной красоты.

throw Error('Pop from empty list');
}
if (!this.tail)
return '';
Copy link
Member

Choose a reason for hiding this comment

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

Просто return

if (this.head) {
return this.head.toString();
}
return 'Empty list';
Copy link
Member

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();
}

}

isEmpty() {
return Boolean(this.length);
Copy link
Member

Choose a reason for hiding this comment

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

return !!this.length;

}

pop() {
if (!this.tail)
Copy link
Member

Choose a reason for hiding this comment

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

{}

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