How do I make sure that when I'm pushing a new node that, if it is already there then it would not be pushed, otherwise push it.
function defineGraph(edges){
// Define the graph
var graph = { nodes: Object.create(null) };
// Define nodes and edges
graph.nodes = []
graph.edges = []
// Add content to graph.nodes and graph.edges
edges.forEach(function (edge) {
var [f, labels, t, att] = edge;
graph.nodes.push({label: f, attributes: att})
graph.nodes.push({label: t, attributes: []})
graph.edges.push([f, t, [labels]])
});
return graph; }
If, it should be of any help my output format is JSON. For example,
"nodes": [
{
"label": "a",
"attributes": [
"initial"
]
}, {...}