Skip to content

Commit 5144332

Browse files
committed
Apply code style
1 parent d2d1c7c commit 5144332

5 files changed

Lines changed: 49 additions & 41 deletions

File tree

JavaScript/1-parent.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

3-
function Node(parent, data) {
4-
this.parent = parent;
5-
this.data = data;
3+
class Node {
4+
constructor(parent, data) {
5+
this.parent = parent;
6+
this.data = data;
7+
}
68
}
79

810
// Usage

JavaScript/2-five.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
'use strict';
22

3-
function Tree(data) {
4-
this.count = 1;
5-
this.root = new Node(null, data);
6-
this.root.tree = this;
7-
}
8-
9-
function Node(parent, data) {
10-
this.data = data;
11-
this.parent = parent;
12-
this.count = 0;
13-
this.prev = null;
14-
this.next = null;
15-
this.first = null;
16-
this.last = null;
17-
if (parent) {
18-
this.tree = parent.tree;
19-
this.tree.count++;
20-
if (!parent.count) {
21-
parent.first = this;
3+
class Node {
4+
constructor(parent, data) {
5+
this.data = data;
6+
this.parent = parent;
7+
this.count = 0;
8+
this.prev = null;
9+
this.next = null;
10+
this.first = null;
11+
this.last = null;
12+
if (parent) {
13+
this.tree = parent.tree;
14+
this.tree.count++;
15+
if (!parent.count) {
16+
parent.first = this;
17+
}
18+
if (parent.last) {
19+
parent.last.next = this;
20+
this.prev = parent.last;
21+
}
22+
parent.last = this;
23+
parent.count++;
2224
}
23-
if (parent.last) {
24-
parent.last.next = this;
25-
this.prev = parent.last;
26-
}
27-
parent.last = this;
28-
parent.count++;
25+
}
26+
27+
add(data) {
28+
return new Node(this, data);
2929
}
3030
}
3131

32-
Node.prototype.add = function(data) {
33-
return new Node(this, data);
34-
};
32+
class Tree {
33+
constructor(data) {
34+
this.count = 1;
35+
this.root = new Node(null, data);
36+
this.root.tree = this;
37+
}
38+
}
3539

3640
// Usage
3741

JavaScript/3-native.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use strict';
22

3-
function Node(parent, name) {
4-
this.name = name;
5-
if (parent) {
6-
this.parent = parent;
7-
parent[name] = this;
3+
class Node {
4+
constructor(parent, name) {
5+
this.name = name;
6+
if (parent) {
7+
this.parent = parent;
8+
parent[name] = this;
9+
}
810
}
911
}
1012

JavaScript/7-bst-over.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ tree.insert = (root, data, i = data < root[0] ? 1 : 2) => (
1010
);
1111

1212
tree.search = (root, data, value = root[0]) => (
13-
data === value || !root ? root :
14-
tree.search(root[data < value ? 1 : 2], data)
13+
data === value || !root ? root
14+
: tree.search(root[data < value ? 1 : 2], data)
1515
);
1616

1717
// Usage

JavaScript/9-bst-ready.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const TREE_LEFT = 3;
77
const TREE_RIGHT = 4;
88

99
const tree = (
10-
key = null, value = null, parent = null, left = null, right = null
10+
key = null, value = null, parent = null, left = null, right = null,
1111
) => [
12-
key, value, parent, left, right
12+
key, value, parent, left, right,
1313
];
1414

1515
const data = (node, key, value) => {
@@ -83,7 +83,7 @@ const del = (root, key) => {
8383
};
8484

8585
Object.assign(tree, {
86-
data, parent, left, right, insert, push, search, get, set, del
86+
data, parent, left, right, insert, push, search, get, set, del,
8787
});
8888

8989
// Usage

0 commit comments

Comments
 (0)