Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 580e3ba

Browse files
committed
fix: empty array throw error
1 parent 599263d commit 580e3ba

File tree

1 file changed

+2
-2
lines changed
  • src/_DataStructures_/Trees/BinaryTree

1 file changed

+2
-2
lines changed

‎src/_DataStructures_/Trees/BinaryTree/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const Node = require('./Node');
22

33
class BinaryTree {
44
constructor(arr) {
5-
if (!Array.isArray(arr)) {
5+
if (!Array.isArray(arr)||!arr.length) {
66
throw new Error('Invalid argument to create a Binary Tre');
77
}
8-
this.root = this.createBinaryTree(this.root, arr, 0);
8+
this.root = this.createBinaryTree((this.root=null), arr, 0);
99
}
1010

1111
// eslint-disable-next-line class-methods-use-this

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /