Skip to content

Instantly share code, notes, and snippets.

@pier-oliviert
Created February 21, 2018 14:53
Show Gist options
  • Select an option

  • Save pier-oliviert/7964ac0afbd1a002aeeddef9f04253e8 to your computer and use it in GitHub Desktop.

Select an option

Save pier-oliviert/7964ac0afbd1a002aeeddef9f04253e8 to your computer and use it in GitHub Desktop.
class Branch {
constructor(nodes) {
this.branches = []
this.nodes = []
_.compact(_.flatten([nodes])).map(node => {
this.insertNode(node)
})
this.dataset = {}
}
get root() {
return _.first(this.nodes)
}
get leaf() {
return _.last(this.nodes)
}
sliceBefore(node) {
return this.slice(this.nodes.indexOf(node))
}
sliceAfter(node) {
return this.slice(this.nodes.indexOf(node) + 1)
}
slice(index) {
const nodes = this.nodes.splice(index)
if (nodes.length > 0) {
const branch = new Branch(nodes)
branch.branches = [...this.branches]
this.branches = [branch]
return branch
}
}
insertNode(target) {
}
removeNode(node) {
}
insertBranch(branch) {
}
removeBranch(branch) {
}
get height() {
return this.nodes.length
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment