Skip to content

Commit

Permalink
Fix max call stack exceeded for getHeight()
Browse files Browse the repository at this point in the history
  • Loading branch information
yishn committed Mar 18, 2020
1 parent 10eed1d commit 6331e41
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/GameTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,16 @@ class GameTree {

getHeight() {
if (this._heightCache == null) {
let inner = node => 1 + Math.max(...node.children.map(inner), 0)
let inner = node => {
let max = 0

for (let child of node.children) {
max = Math.max(max, inner(child))
}

return max + 1
}

this._heightCache = inner(this.root)
}

Expand Down

0 comments on commit 6331e41

Please sign in to comment.