Skip to content

Added Binary Tree #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 17, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: empty array throw error
  • Loading branch information
ashokdey committed Oct 17, 2019
commit 580e3ba89d9789bec861af4f2887959db4427040
4 changes: 2 additions & 2 deletions src/_DataStructures_/Trees/BinaryTree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const Node = require('./Node');

class BinaryTree {
constructor(arr) {
if (!Array.isArray(arr)) {
if (!Array.isArray(arr) || !arr.length) {
throw new Error('Invalid argument to create a Binary Tre');
}
this.root = this.createBinaryTree(this.root, arr, 0);
this.root = this.createBinaryTree((this.root = null), arr, 0);
}

// eslint-disable-next-line class-methods-use-this
Expand Down