From 30948b1750c137d1c70aaf734fc92312e1282194 Mon Sep 17 00:00:00 2001 From: Zak Tsai Date: Mon, 1 Sep 2014 23:06:45 -0500 Subject: [PATCH] Use filter instead of manually create new array --- lib/bst.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/bst.js b/lib/bst.js index 2276f67..0533a90 100644 --- a/lib/bst.js +++ b/lib/bst.js @@ -433,9 +433,7 @@ BinarySearchTree.prototype.deleteIfOnlyOneChild = function () { * @param {Value} value Optional. If not set, the whole key is deleted. If set, only this value is deleted */ BinarySearchTree.prototype.delete = function (key, value) { - var newData = [], replaceWith - , self = this - ; + var replaceWith; if (!this.hasOwnProperty('key')) { return; } @@ -453,10 +451,9 @@ BinarySearchTree.prototype.delete = function (key, value) { // Delete only a value if (this.data.length > 1 && value !== undefined) { - this.data.forEach(function (d) { - if (!self.checkValueEquality(d, value)) { newData.push(d); } - }); - self.data = newData; + this.data = this.data.filter(function(d) { + return !this.checkValueEquality(d, value); + }, this); return; }