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; }