1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | const getAdjacentNodeIds = (edges, nodeId) => {
|
10 | let adjacentNodeIds = []
|
11 |
|
12 | const givenNodeId = (id) => {
|
13 | return id !== nodeId
|
14 | }
|
15 |
|
16 | const foundNodeIds = (id) => {
|
17 | return adjacentNodeIds.indexOf(id) === -1
|
18 | }
|
19 |
|
20 | for (let edgeId in edges) {
|
21 | let edge = edges[edgeId]
|
22 |
|
23 |
|
24 | if (edge.indexOf(nodeId) === -1) continue
|
25 |
|
26 |
|
27 | let nodeIds = edge.filter(givenNodeId)
|
28 | .filter(foundNodeIds)
|
29 |
|
30 | adjacentNodeIds = adjacentNodeIds.concat(nodeIds)
|
31 | }
|
32 |
|
33 | return adjacentNodeIds
|
34 | }
|
35 |
|
36 | module.exports = getAdjacentNodeIds
|