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 0ce38b6

Browse files
add eslint
1 parent 446f1a5 commit 0ce38b6

16 files changed

+311
-83
lines changed

‎.eslintrc.json

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
{
2+
"parserOptions": {
3+
"sourceType": "module"
4+
},
5+
"env": {
6+
"es6": true,
7+
"node": true
8+
},
9+
"globals": {
10+
"window": true,
11+
"document": true,
12+
"fetch": true,
13+
"Headers": true,
14+
"Request": true,
15+
"FormData": true,
16+
"FileReader": true,
17+
"localStorage": true
18+
},
19+
"rules": {
20+
"block-scoped-var": [0],
21+
"brace-style": [2, "1tbs", {
22+
"allowSingleLine": true
23+
}],
24+
"camelcase": [0],
25+
"comma-dangle": [0],
26+
"comma-spacing": [2],
27+
"comma-style": [2, "last"],
28+
"complexity": [0, 11],
29+
"consistent-return": [2],
30+
"consistent-this": [0, "that"],
31+
"curly": [2, "multi-line"],
32+
"default-case": [2],
33+
"dot-notation": [2, {
34+
"allowKeywords": true
35+
}],
36+
"eol-last": [2],
37+
"eqeqeq": [2],
38+
"func-names": [0],
39+
"func-style": [0, "declaration"],
40+
"generator-star-spacing": [2, "after"],
41+
"guard-for-in": [0],
42+
"handle-callback-err": [0],
43+
"indent": [2, 2, {
44+
"SwitchCase": 1,
45+
"VariableDeclarator": 2
46+
}
47+
],
48+
"key-spacing": [2, {
49+
"beforeColon": false,
50+
"afterColon": true
51+
}],
52+
"quotes": [2, "single", "avoid-escape"],
53+
"max-depth": [0, 4],
54+
"max-len": [0, 80, 4],
55+
"max-nested-callbacks": [0, 2],
56+
"max-params": [0, 3],
57+
"max-statements": [0, 10],
58+
"new-parens": [2],
59+
"new-cap": [0],
60+
"newline-after-var": [0],
61+
"no-alert": [2],
62+
"no-array-constructor": [2],
63+
"no-bitwise": [0],
64+
"no-caller": [2],
65+
"no-catch-shadow": [2],
66+
"no-cond-assign": [2],
67+
"no-console": [0],
68+
"no-constant-condition": [1],
69+
"no-continue": [2],
70+
"no-control-regex": [2],
71+
"no-debugger": [2],
72+
"no-delete-var": [2],
73+
"no-div-regex": [0],
74+
"no-dupe-args": [2],
75+
"no-dupe-keys": [2],
76+
"no-duplicate-case": [2],
77+
"no-else-return": [0],
78+
"no-empty": [2],
79+
"no-empty-character-class": [2],
80+
"no-eq-null": [0],
81+
"no-eval": [2],
82+
"no-ex-assign": [2],
83+
"no-extend-native": [1],
84+
"no-extra-bind": [2],
85+
"no-extra-boolean-cast": [2],
86+
"no-extra-parens": [0],
87+
"no-extra-semi": [1],
88+
"no-fallthrough": [2],
89+
"no-floating-decimal": [2],
90+
"no-func-assign": [2],
91+
"no-implied-eval": [2],
92+
"no-inline-comments": [0],
93+
"no-inner-declarations": [2, "functions"],
94+
"no-invalid-regexp": [2],
95+
"no-irregular-whitespace": [2],
96+
"no-iterator": [2],
97+
"no-label-var": [2],
98+
"no-labels": [2],
99+
"no-lone-blocks": [2],
100+
"no-lonely-if": [2],
101+
"no-loop-func": [2],
102+
"no-mixed-requires": [0, false],
103+
"no-mixed-spaces-and-tabs": [2, false],
104+
"no-multi-spaces": [2],
105+
"no-multi-str": [2],
106+
"no-multiple-empty-lines": [2, {
107+
"max": 1
108+
}],
109+
"no-native-reassign": [1],
110+
"no-negated-in-lhs": [2],
111+
"no-nested-ternary": [0],
112+
"no-new": [0],
113+
"no-new-func": [2],
114+
"no-new-object": [2],
115+
"no-new-require": [0],
116+
"no-new-wrappers": [2],
117+
"no-obj-calls": [2],
118+
"no-octal": [2],
119+
"no-octal-escape": [2],
120+
"no-param-reassign": [0],
121+
"no-path-concat": [0],
122+
"no-plusplus": [0],
123+
"no-process-env": [0],
124+
"no-process-exit": [0],
125+
"no-proto": [2],
126+
"no-redeclare": [2],
127+
"no-regex-spaces": [2],
128+
"no-reserved-keys": [0],
129+
"no-restricted-modules": [0],
130+
"no-return-assign": [2],
131+
"no-script-url": [2],
132+
"no-self-compare": [0],
133+
"no-sequences": [2],
134+
"no-shadow": [2],
135+
"no-shadow-restricted-names": [2],
136+
"no-spaced-func": [2],
137+
"no-sparse-arrays": [2],
138+
"no-sync": [0],
139+
"no-ternary": [0],
140+
"no-throw-literal": [2],
141+
"no-trailing-spaces": [2, {"skipBlankLines": true}],
142+
"no-undef": [2],
143+
"no-undef-init": [2],
144+
"no-undefined": [0],
145+
"no-underscore-dangle": [0],
146+
"no-unreachable": [2],
147+
"no-unused-expressions": [2],
148+
"no-unused-vars": [2, {
149+
"vars": "all",
150+
"args": "after-used"
151+
}],
152+
"no-use-before-define": [0],
153+
"no-void": [0],
154+
"no-warning-comments": [0, {
155+
"terms": ["todo", "fixme", "xxx"],
156+
"location": "start"
157+
}],
158+
"no-with": [2],
159+
"object-curly-spacing": [2, "always"],
160+
"one-var": [1],
161+
"operator-assignment": [0, "always"],
162+
"operator-linebreak": [2, "before"],
163+
"padded-blocks": [0],
164+
"prefer-template": [2],
165+
"quote-props": [0],
166+
"radix": [0],
167+
"semi": [0],
168+
"sort-vars": [0],
169+
"keyword-spacing": [2, {"before": true, "after": true}],
170+
"space-before-function-paren": [2, {
171+
"anonymous": "never",
172+
"named": "never"
173+
}],
174+
"space-before-blocks": [0, "always"],
175+
"space-in-brackets": [
176+
0, "never", {
177+
"singleValue": true,
178+
"arraysInArrays": false,
179+
"arraysInObjects": false,
180+
"objectsInArrays": true,
181+
"objectsInObjects": true,
182+
"propertyName": false
183+
}
184+
],
185+
"space-in-parens": [2, "never"],
186+
"space-infix-ops": [2],
187+
"space-unary-ops": [2, {
188+
"words": true,
189+
"nonwords": false
190+
}],
191+
"spaced-line-comment": [0, "always"],
192+
"strict": 0,
193+
"use-isnan": [2],
194+
"valid-jsdoc": [0],
195+
"valid-typeof": [2],
196+
"vars-on-top": [0],
197+
"wrap-iife": [2],
198+
"wrap-regex": [2],
199+
"yoda": [2, "never", {
200+
"exceptRange": true
201+
}]
202+
}
203+
}

‎data-structures/binary-search-tree.js

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,38 @@ function BST() {
1111
this.root = null
1212
}
1313

14-
BST.prototype.insert = function(value) {
14+
BST.prototype.insert = function(value) {
1515
let node = new Node(value),
1616
current = null,
1717
x = this.root
1818

1919
while (x !== null) {
2020
current = x
21-
if (node.key < x.key)
21+
if (node.key < x.key){
2222
x = x.left
23-
else
23+
}else{
2424
x = x.right
25+
}
2526
}
2627

27-
if (current === null)
28+
if (current === null){
2829
this.root = node
29-
else if (node.key < current.key)
30+
}else if (node.key < current.key){
3031
current.left = node
31-
else
32+
}else{
3233
current.right = node
33-
34+
}
3435
node.parent = current
3536
}
3637

37-
BST.prototype.delete = function(value) {
38+
BST.prototype.delete = function(value) {
3839
let current = this.search(value)
3940

40-
if (!current.left)
41+
if (!current.left){
4142
this.transplant(current, current.right)
42-
else if (!current.right)
43+
}else if (!current.right){
4344
this.transplant(current, current.left)
44-
else {
45+
}else {
4546
let y = this.min(current.right)
4647

4748
if (y.parent !== current) {
@@ -55,84 +56,95 @@ BST.prototype.delete = function (value) {
5556
}
5657
}
5758

58-
BST.prototype.transplant = function(u, v) {
59-
if (!u.parent)
59+
BST.prototype.transplant = function(u, v) {
60+
if (!u.parent){
6061
this.root = v
61-
else if (u === u.parent.left)
62+
}else if (u === u.parent.left){
6263
u.parent.left = v
63-
else
64+
}else{
6465
u.parent.right = v
66+
}
6567
if (v) {
6668
v.parent = u.parent
6769
}
6870
}
6971

70-
BST.prototype.search = function(value) {
72+
BST.prototype.search = function(value) {
7173
let current = this.root
7274
while (current) {
73-
if (value === current.key)
75+
if (value === current.key){
7476
return current
75-
else if (value < current.key)
77+
}else if (value < current.key){
7678
current = current.left
77-
else
79+
}else{
7880
current = current.right
81+
}
7982
}
83+
8084
return null
8185
}
8286

83-
BST.prototype.min = function(node) {
84-
while (node.left)
87+
BST.prototype.min = function(node) {
88+
while (node.left){
8589
node = node.left
90+
}
8691

8792
return node
8893
}
8994

90-
BST.prototype.max = function(node) {
91-
while (node.right)
95+
BST.prototype.max = function(node) {
96+
while (node.right){
9297
node = node.right
98+
}
9399

94100
return node
95101
}
96102

97103
BST.prototype.sucessor = function(value) {
98104
let current = this.search(value)
99-
if (current.right)
105+
if (current.right){
100106
return this.min(current.right)
107+
}
101108

102-
while (current.parent && current === current.parent.right)
109+
while (current.parent && current === current.parent.right){
103110
current = current.parent
111+
}
104112

105113
return current.parent
106114
}
107115

108116
BST.prototype.predecessor = function(value) {
109117
let current = this.search(value)
110-
if (current.left)
118+
if (current.left){
111119
return this.max(current.left)
120+
}
112121

113-
while (current.parent && current === current.parent.left)
122+
while (current.parent && current === current.parent.left){
114123
current = current.parent
124+
}
115125

116126
return current.parent
117127
}
118128

119-
BST.prototype.length = function() {
129+
BST.prototype.length = function() {
120130
let count = 0
121131
this.inorderTreeWalk(this.root, function() {
122132
count++
123133
})
134+
124135
return count
125136
}
126137

127-
BST.prototype.toArray = function() {
138+
BST.prototype.toArray = function() {
128139
let result = []
129140
this.inorderTreeWalk(this.root, function(key) {
130141
result.push(key)
131142
})
143+
132144
return result
133145
}
134146

135-
BST.prototype.inorderTreeWalk = function(node, callback) {
147+
BST.prototype.inorderTreeWalk = function(node, callback) {
136148
if (node) {
137149
this.inorderTreeWalk(node.left, callback)
138150
callback(node.key)
@@ -151,7 +163,7 @@ test('BST', assert => {
151163
assert.deepEqual(bst.search(15).key, 15)
152164
assert.deepEqual(bst.min(bst.root).key, 4)
153165
assert.deepEqual(bst.max(bst.root).key, 15)
154-
assert.deepEqual(bst.toArray(), [4,8,12,15])
166+
assert.deepEqual(bst.toArray(), [4,8,12,15])
155167
assert.deepEqual(bst.length(), 4)
156168
assert.deepEqual(bst.root.left.parent.key, 12)
157169
assert.deepEqual(bst.sucessor(12).key, 15)
@@ -162,7 +174,7 @@ test('BST', assert => {
162174
assert.deepEqual(bst.predecessor(4), null)
163175
bst.delete(12)
164176
assert.deepEqual(bst.search(12), null)
165-
assert.deepEqual(bst.toArray(), [4,8,15])
177+
assert.deepEqual(bst.toArray(), [4,8,15])
166178
assert.deepEqual(bst.root.left.parent.key, 15)
167179
assert.deepEqual(bst.length(), 3)
168180
assert.end()

0 commit comments

Comments
(0)

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