MCPcopy
hub / github.com/TheAlgorithms/JavaScript / nodeNeighbors

Method nodeNeighbors

Graphs/NodeNeighbors.js:17–30  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

15 }
16
17 nodeNeighbors(node) {
18 // Returns an array with all of the node neighbors
19 const neighbors = new Set()
20 for (const edge of this.edges) {
21 // Checks if they have an edge between them and if the neighbor is not
22 // already in the neighbors array
23 if (edge.node1 === node && !neighbors.has(edge.node2)) {
24 neighbors.add(edge.node2)
25 } else if (edge.node2 === node && !neighbors.has(edge.node1)) {
26 neighbors.add(edge.node1)
27 }
28 }
29 return neighbors
30 }
31}
32
33export { Graph }

Callers

nothing calls this directly

Calls 2

hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected