This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Description
I learned binary-search-tree.js today. I found a duplicate code which is very obvious.
https://github.com/blakeembrey/code-problems/blob/master/solutions/javascript/binary-search-tree.js
if we refactored in this way:
doSubNode = function(direct, num) {
if (this[direct] === undefined) {
this[direct] = createNode(num);
} else {
this[direct].add(num);
}
};
and used it in:
...
if (num < this.value) {
doSubNode.apply(this,["left", num]);
} else if (num > this.value) {
doSubNode.apply(this,["right", num]);
}
...
So is any reason to use the duplicated code? or it's OK to refactor the code?