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

is the refactor of the binary-search-tree.js ok? #101

@caoglish

Description

@caoglish

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions