Skip to content

Commit 0a8d032

Browse files
committed
Using Object.hasOwn instead of hasOwnProperty
1 parent 19cd7c0 commit 0a8d032

File tree

8 files changed

+20
-20
lines changed

8 files changed

+20
-20
lines changed

lib/alg/components.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function components(g) {
66
var cmpt;
77

88
function dfs(v) {
9-
if (visited.hasOwnProperty(v)) return;
9+
if (Object.hasOwn(visited, v)) return;
1010
visited[v] = true;
1111
cmpt.push(v);
1212
g.successors(v).forEach(dfs);

lib/alg/dfs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function postOrderDfs(v, navigation, visited, acc) {
3636
if (curr[1]) {
3737
acc.push(curr[0]);
3838
} else {
39-
if (!visited.hasOwnProperty(curr[0])) {
39+
if (!Object.hasOwn(visited, curr[0])) {
4040
visited[curr[0]] = true;
4141
stack.push([curr[0], true]);
4242
forEachRight(navigation(curr[0]), w => stack.push([w, false]));
@@ -49,7 +49,7 @@ function preOrderDfs(v, navigation, visited, acc) {
4949
var stack = [v];
5050
while (stack.length > 0) {
5151
var curr = stack.pop();
52-
if (!visited.hasOwnProperty(curr)) {
52+
if (!Object.hasOwn(visited, curr)) {
5353
visited[curr] = true;
5454
acc.push(curr);
5555
forEachRight(navigation(curr), w => stack.push(w));

lib/alg/prim.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function prim(g, weightFunc) {
3636
var init = false;
3737
while (pq.size() > 0) {
3838
v = pq.removeMin();
39-
if (parents.hasOwnProperty(v)) {
39+
if (Object.hasOwn(parents, v)) {
4040
result.setEdge(v, parents[v]);
4141
} else if (init) {
4242
throw new Error("Input graph is not connected: " + g);

lib/alg/tarjan.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function tarjan(g) {
1515
stack.push(v);
1616

1717
g.successors(v).forEach(function(w) {
18-
if (!visited.hasOwnProperty(w)) {
18+
if (!Object.hasOwn(visited, w)) {
1919
dfs(w);
2020
entry.lowlink = Math.min(entry.lowlink, visited[w].lowlink);
2121
} else if (visited[w].onStack) {
@@ -36,7 +36,7 @@ function tarjan(g) {
3636
}
3737

3838
g.nodes().forEach(function(v) {
39-
if (!visited.hasOwnProperty(v)) {
39+
if (!Object.hasOwn(visited, v)) {
4040
dfs(v);
4141
}
4242
});

lib/alg/topsort.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ function topsort(g) {
44
var results = [];
55

66
function visit(node) {
7-
if (stack.hasOwnProperty(node)) {
7+
if (Object.hasOwn(stack, node)) {
88
throw new CycleException();
99
}
1010

11-
if (!visited.hasOwnProperty(node)) {
11+
if (!Object.hasOwn(visited, node)) {
1212
stack[node] = true;
1313
visited[node] = true;
1414
g.predecessors(node).forEach(visit);

lib/data/priority-queue.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PriorityQueue {
2727
* Returns `true` if **key** is in the queue and `false` if not.
2828
*/
2929
has(key) {
30-
return this._keyIndices.hasOwnProperty(key);
30+
return Object.hasOwn(this._keyIndices, key);
3131
}
3232

3333
/**
@@ -65,7 +65,7 @@ class PriorityQueue {
6565
add(key, priority) {
6666
var keyIndices = this._keyIndices;
6767
key = String(key);
68-
if (!keyIndices.hasOwnProperty(key)) {
68+
if (!Object.hasOwn(keyIndices, key)) {
6969
var arr = this._arr;
7070
var index = arr.length;
7171
keyIndices[key] = index;

lib/graph.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class Graph {
6161

6262
constructor(opts) {
6363
if (opts) {
64-
this._isDirected = opts.hasOwnProperty("directed") ? opts.directed : true;
65-
this._isMultigraph = opts.hasOwnProperty("multigraph") ? opts.multigraph : false;
66-
this._isCompound = opts.hasOwnProperty("compound") ? opts.compound : false;
64+
this._isDirected = Object.hasOwn(opts, "directed") ? opts.directed : true;
65+
this._isMultigraph = Object.hasOwn(opts, "multigraph") ? opts.multigraph : false;
66+
this._isCompound = Object.hasOwn(opts, "compound") ? opts.compound : false;
6767
}
6868

6969
if (this._isCompound) {
@@ -192,7 +192,7 @@ class Graph {
192192
* Complexity: O(1).
193193
*/
194194
setNode(v, value) {
195-
if (this._nodes.hasOwnProperty(v)) {
195+
if (Object.hasOwn(this._nodes, v)) {
196196
if (arguments.length > 1) {
197197
this._nodes[v] = value;
198198
}
@@ -225,7 +225,7 @@ class Graph {
225225
* Detects whether graph has a node with specified name or not.
226226
*/
227227
hasNode(v) {
228-
return this._nodes.hasOwnProperty(v);
228+
return Object.hasOwn(this._nodes, v);
229229
}
230230

231231
/**
@@ -236,7 +236,7 @@ class Graph {
236236
*/
237237
removeNode(v) {
238238
var self = this;
239-
if (this._nodes.hasOwnProperty(v)) {
239+
if (Object.hasOwn(this._nodes, v)) {
240240
var removeEdge = e => self.removeEdge(self._edgeObjs[e]);
241241
delete this._nodes[v];
242242
if (this._isCompound) {
@@ -514,7 +514,7 @@ class Graph {
514514
}
515515

516516
var e = edgeArgsToId(this._isDirected, v, w, name);
517-
if (this._edgeLabels.hasOwnProperty(e)) {
517+
if (Object.hasOwn(this._edgeLabels, e)) {
518518
if (valueSpecified) {
519519
this._edgeLabels[e] = value;
520520
}
@@ -579,7 +579,7 @@ class Graph {
579579
var e = (arguments.length === 1
580580
? edgeObjToId(this._isDirected, arguments[0])
581581
: edgeArgsToId(this._isDirected, v, w, name));
582-
return this._edgeLabels.hasOwnProperty(e);
582+
return Object.hasOwn(this._edgeLabels, e);
583583
}
584584

585585
/**

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)