1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | const getIncidentEdgeIds = (edges, nodeId) => {
|
10 | let incidentEdgeIds = []
|
11 |
|
12 | const pushUniqueIncidents = (edgeId, nodeId, id) => {
|
13 | let isIncident = (id === nodeId)
|
14 | let isUnique = (incidentEdgeIds.indexOf(edgeId) < 0)
|
15 |
|
16 | if (isIncident && isUnique)
|
17 | incidentEdgeIds.push(edgeId)
|
18 | }
|
19 |
|
20 | for (let edgeId in edges) {
|
21 | let edge = edges[edgeId]
|
22 |
|
23 | edge.forEach(pushUniqueIncidents.bind(null, edgeId, nodeId))
|
24 | }
|
25 |
|
26 | return incidentEdgeIds
|
27 | }
|
28 |
|
29 | module.exports = getIncidentEdgeIds
|