diff --git a/lib/bst.js b/lib/bst.js index 2276f67..98bcb16 100644 --- a/lib/bst.js +++ b/lib/bst.js @@ -328,16 +328,6 @@ BinarySearchTree.prototype.getUpperBoundMatcher = function (query) { }; -// Append all elements in toAppend to array -function append (array, toAppend) { - var i; - - for (i = 0; i < toAppend.length; i += 1) { - array.push(toAppend[i]); - } -} - - /** * Get all data for a key between bounds * Return it in key order @@ -352,9 +342,9 @@ BinarySearchTree.prototype.betweenBounds = function (query, lbm, ubm) { lbm = lbm || this.getLowerBoundMatcher(query); ubm = ubm || this.getUpperBoundMatcher(query); - if (lbm(this.key) && this.left) { append(res, this.left.betweenBounds(query, lbm, ubm)); } - if (lbm(this.key) && ubm(this.key)) { append(res, this.data); } - if (ubm(this.key) && this.right) { append(res, this.right.betweenBounds(query, lbm, ubm)); } + if (lbm(this.key) && this.left) { res = res.concat(this.left.betweenBounds(query, lbm, ubm)); } + if (lbm(this.key) && ubm(this.key)) { res = res.concat(this.data); } + if (ubm(this.key) && this.right) { res = res.concat(this.right.betweenBounds(query, lbm, ubm)); } return res; };