-
Notifications
You must be signed in to change notification settings - Fork 13
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
Implemented tree using classes, additional functionality #8
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.
В общем код достаточно внятный и чистый
JavaScript/4-class.js
Outdated
} | ||
|
||
findAll(name) { // Find all nodes with specified name | ||
let arr = []; |
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.
const
JavaScript/4-class.js
Outdated
find(name, callback) { //Call function for each found node | ||
const nodes = this.findAll(name); | ||
if (nodes.length > 0) | ||
for (let n of this.findAll(name)) |
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 и for
JavaScript/4-class.js
Outdated
} | ||
|
||
setParent(newParent) { // Sets new parent for this node | ||
this.parent.childs.pop(this.parent.childs.indexOf(this)); |
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/4-class.js
Outdated
|
||
console.log('findAll("searched") -', root.findAll('searched')); | ||
console.log('findFirst("searched") -', root.findFirst('searched')); | ||
root.find('n2', n => { |
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.
Вот тут {} можно опустить
n => console.log(...
JavaScript/4-class.js
Outdated
findAll(name) { // Find all nodes with specified name | ||
let arr = []; | ||
if (this.name === name) arr.push(this); | ||
for (let n of this.childs) { |
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.
Тут ходить по массиву обычным циклом, for..of пока медленный
JavaScript/4-class.js
Outdated
|
||
findFirst(name) { //Find first instance | ||
if (this.name === name) return this; | ||
for (let n of this.childs) { |
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.
тоже без for..of лучше избавиться, а переменную содавать до цикла:
let i;
for (i = 0; ...
это работает быстрее
Implemented tree using ES6 classes, added next methods: