UNPKG

623 BJavaScriptView Raw
1/**
2 * Edges incident to given node
3 *
4 * @param {Array} edges
5 * @param {String} nodeId
6 * @returns {Array} incidentEdgeIds
7 */
8
9const 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
29module.exports = getIncidentEdgeIds