From 3412cc42a9fa5e42d47073a2fa05a39712ad40f7 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 16 Apr 2014 15:08:44 -0400 Subject: layer of indirection for rooms --- assets/javascripts/rectangles/tree.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'assets/javascripts/rectangles/tree.js') diff --git a/assets/javascripts/rectangles/tree.js b/assets/javascripts/rectangles/tree.js index f5eb117..577c41a 100644 --- a/assets/javascripts/rectangles/tree.js +++ b/assets/javascripts/rectangles/tree.js @@ -15,6 +15,13 @@ tree.prototype.add = function(n, data){ if (n < closest.value) return closest.lo = new tree(n, data) if (n > closest.value) return closest.hi = new tree(n, data) } +tree.prototype.toArray = function(){ + var a = [] + if (this.lo) a = a.concat(this.lo.toArray()) + a.push(this.data) + if (this.hi) a = a.concat(this.hi.toArray()) + return a +} tree.prototype.toString = function(){ var s = ""; if (this.lo) s += this.lo.toString() -- cgit v1.2.3-70-g09d2