From 7b15f66a8695dc654072ce368c9166ffe2244eca Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Wed, 6 Jan 2021 17:37:19 -0300 Subject: [PATCH] Added JS standard --- Graphs/NodeNeighbors.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Graphs/NodeNeighbors.js b/Graphs/NodeNeighbors.js index 54ec4b63a..473cdf0f1 100644 --- a/Graphs/NodeNeighbors.js +++ b/Graphs/NodeNeighbors.js @@ -1,12 +1,12 @@ // https://en.wikipedia.org/wiki/Neighbourhood_(graph_theory) -class Graph{ +class Graph { // Generic graph: the algorithm works regardless of direction or weight - constructor(){ + constructor () { this.edges = [] } - addEdge(node1, node2){ + addEdge (node1, node2) { // Adding edges to the graph this.edges.push({ node1, @@ -14,16 +14,15 @@ class Graph{ }) } - nodeNeighbors(node){ + nodeNeighbors (node) { // Returns an array with all of the node neighbors - let neighbors = [] + const neighbors = [] for (let i = 0; i < this.edges.length; i++) { // Checks if they have an edge between them and if the neighbor is not // already in the neighbors array if (this.edges[i].node1 === node && !(neighbors.includes(this.edges[i].node2))) { neighbors.push(this.edges[i].node2) - } - else if (this.edges[i].node2 === node && !(neighbors.includes(this.edges[i].node1))) { + } else if (this.edges[i].node2 === node && !(neighbors.includes(this.edges[i].node1))) { neighbors.push(this.edges[i].node1) } } @@ -32,7 +31,7 @@ class Graph{ } (() => { - let graph = new Graph() + const graph = new Graph() graph.addEdge(1, 2) graph.addEdge(2, 3) graph.addEdge(3, 5)