JSFiddle - React, Tailwind, and code Playground
by Cal Francesco
JavaScript
edges = [
{
"source": "A",
"target": "B",
"other information" : "randomstring",
"other information2" : "randomstring"
},{
"source": "A",
"target": "C",
"other information" : "randomstring",
"other information2" : "randomstring"
},{
"source": "B",
"target": "C",
"other information" : "randomstring",
"other information2" : "randomstring"
},{
"source": "D",
"target": "C",
"other information" : "randomstring",
"other information2" : "randomstring"
},{
"source": "C",
"target": "E",
"other information2" : "randomstring",
"other information" : "randomstring"
}
]
var res = edges.reduce(function (acc, cur, i, array) {
if (array[i - 1] == undefined || acc[acc.length - 1].target == cur.source) {
acc.push(cur)
}
return acc
}, [])
console.log(res)