diff --git a/lib/alg/components.js b/lib/alg/components.js index deeb85ed..df4f9e87 100644 --- a/lib/alg/components.js +++ b/lib/alg/components.js @@ -6,7 +6,7 @@ function components(g) { var cmpt; function dfs(v) { - if (visited.hasOwnProperty(v)) return; + if (Object.hasOwn(visited, v)) return; visited[v] = true; cmpt.push(v); g.successors(v).forEach(dfs); diff --git a/lib/alg/dfs.js b/lib/alg/dfs.js index 34a323cb..447f6a74 100644 --- a/lib/alg/dfs.js +++ b/lib/alg/dfs.js @@ -36,7 +36,7 @@ function postOrderDfs(v, navigation, visited, acc) { if (curr[1]) { acc.push(curr[0]); } else { - if (!visited.hasOwnProperty(curr[0])) { + if (!Object.hasOwn(visited, curr[0])) { visited[curr[0]] = true; stack.push([curr[0], true]); forEachRight(navigation(curr[0]), w => stack.push([w, false])); @@ -49,7 +49,7 @@ function preOrderDfs(v, navigation, visited, acc) { var stack = [v]; while (stack.length > 0) { var curr = stack.pop(); - if (!visited.hasOwnProperty(curr)) { + if (!Object.hasOwn(visited, curr)) { visited[curr] = true; acc.push(curr); forEachRight(navigation(curr), w => stack.push(w)); diff --git a/lib/alg/prim.js b/lib/alg/prim.js index 72fcd841..e9ec3e4d 100644 --- a/lib/alg/prim.js +++ b/lib/alg/prim.js @@ -36,7 +36,7 @@ function prim(g, weightFunc) { var init = false; while (pq.size() > 0) { v = pq.removeMin(); - if (parents.hasOwnProperty(v)) { + if (Object.hasOwn(parents, v)) { result.setEdge(v, parents[v]); } else if (init) { throw new Error("Input graph is not connected: " + g); diff --git a/lib/alg/tarjan.js b/lib/alg/tarjan.js index c00eeba7..a6146df0 100644 --- a/lib/alg/tarjan.js +++ b/lib/alg/tarjan.js @@ -15,7 +15,7 @@ function tarjan(g) { stack.push(v); g.successors(v).forEach(function(w) { - if (!visited.hasOwnProperty(w)) { + if (!Object.hasOwn(visited, w)) { dfs(w); entry.lowlink = Math.min(entry.lowlink, visited[w].lowlink); } else if (visited[w].onStack) { @@ -36,7 +36,7 @@ function tarjan(g) { } g.nodes().forEach(function(v) { - if (!visited.hasOwnProperty(v)) { + if (!Object.hasOwn(visited, v)) { dfs(v); } }); diff --git a/lib/alg/topsort.js b/lib/alg/topsort.js index 5986ce02..082044fe 100644 --- a/lib/alg/topsort.js +++ b/lib/alg/topsort.js @@ -4,11 +4,11 @@ function topsort(g) { var results = []; function visit(node) { - if (stack.hasOwnProperty(node)) { + if (Object.hasOwn(stack, node)) { throw new CycleException(); } - if (!visited.hasOwnProperty(node)) { + if (!Object.hasOwn(visited, node)) { stack[node] = true; visited[node] = true; g.predecessors(node).forEach(visit); diff --git a/lib/data/priority-queue.js b/lib/data/priority-queue.js index 6ce46fe8..d0836561 100644 --- a/lib/data/priority-queue.js +++ b/lib/data/priority-queue.js @@ -27,7 +27,7 @@ class PriorityQueue { * Returns `true` if **key** is in the queue and `false` if not. */ has(key) { - return this._keyIndices.hasOwnProperty(key); + return Object.hasOwn(this._keyIndices, key); } /** @@ -65,7 +65,7 @@ class PriorityQueue { add(key, priority) { var keyIndices = this._keyIndices; key = String(key); - if (!keyIndices.hasOwnProperty(key)) { + if (!Object.hasOwn(keyIndices, key)) { var arr = this._arr; var index = arr.length; keyIndices[key] = index; diff --git a/lib/graph.js b/lib/graph.js index da9fa731..c593dc71 100644 --- a/lib/graph.js +++ b/lib/graph.js @@ -61,9 +61,9 @@ class Graph { constructor(opts) { if (opts) { - this._isDirected = opts.hasOwnProperty("directed") ? opts.directed : true; - this._isMultigraph = opts.hasOwnProperty("multigraph") ? opts.multigraph : false; - this._isCompound = opts.hasOwnProperty("compound") ? opts.compound : false; + this._isDirected = Object.hasOwn(opts, "directed") ? opts.directed : true; + this._isMultigraph = Object.hasOwn(opts, "multigraph") ? opts.multigraph : false; + this._isCompound = Object.hasOwn(opts, "compound") ? opts.compound : false; } if (this._isCompound) { @@ -192,7 +192,7 @@ class Graph { * Complexity: O(1). */ setNode(v, value) { - if (this._nodes.hasOwnProperty(v)) { + if (Object.hasOwn(this._nodes, v)) { if (arguments.length > 1) { this._nodes[v] = value; } @@ -225,7 +225,7 @@ class Graph { * Detects whether graph has a node with specified name or not. */ hasNode(v) { - return this._nodes.hasOwnProperty(v); + return Object.hasOwn(this._nodes, v); } /** @@ -236,7 +236,7 @@ class Graph { */ removeNode(v) { var self = this; - if (this._nodes.hasOwnProperty(v)) { + if (Object.hasOwn(this._nodes, v)) { var removeEdge = e => self.removeEdge(self._edgeObjs[e]); delete this._nodes[v]; if (this._isCompound) { @@ -514,7 +514,7 @@ class Graph { } var e = edgeArgsToId(this._isDirected, v, w, name); - if (this._edgeLabels.hasOwnProperty(e)) { + if (Object.hasOwn(this._edgeLabels, e)) { if (valueSpecified) { this._edgeLabels[e] = value; } @@ -579,7 +579,7 @@ class Graph { var e = (arguments.length === 1 ? edgeObjToId(this._isDirected, arguments[0]) : edgeArgsToId(this._isDirected, v, w, name)); - return this._edgeLabels.hasOwnProperty(e); + return Object.hasOwn(this._edgeLabels, e); } /**