We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 599263d commit 580e3baCopy full SHA for 580e3ba
src/_DataStructures_/Trees/BinaryTree/index.js
@@ -2,10 +2,10 @@ const Node = require('./Node');
2
3
class BinaryTree {
4
constructor(arr) {
5
- if (!Array.isArray(arr)) {
+ if (!Array.isArray(arr) || !arr.length) {
6
throw new Error('Invalid argument to create a Binary Tre');
7
}
8
- this.root = this.createBinaryTree(this.root, arr, 0);
+ this.root = this.createBinaryTree((this.root = null), arr, 0);
9
10
11
// eslint-disable-next-line class-methods-use-this
0 commit comments