Skip to content

ES6 Tree Remove. Sibling to removed node is not added to BFS queue #5

Open
@tenthirtyone

Description

@tenthirtyone

https://github.com/benoitvallon/computer-science-in-javascript/blob/master/data-structures-in-javascript/tree.es6.js#L33

Splice in the for loop shifts the elements in the array and skips the sibling of the node that was removed.

Fix PR:

You can test with:

const tree = new Tree();
tree.add('ceo');
tree.add('cto1', 'ceo');
tree.add('cto2', 'ceo');
tree.add('cto3', 'ceo');
tree.add('dev1', 'cto1');
tree.add('dev2', 'cto1');
tree.add('dev3', 'cto1');
tree.add('dev2', 'dev3');
tree.add('dev1', 'cto2');
tree.add('dev2', 'cto2');
tree.add('dev3', 'cto2');
tree.add('dev1', 'cto3');
tree.add('dev2', 'cto3');
tree.add('dev3', 'cto3');
tree.printByLevel();
tree.remove('dev2');
tree.printByLevel();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      ES6 Tree Remove. Sibling to removed node is not added to BFS queue · Issue #5 · benoitvallon/computer-science-in-javascript