I have the following array of objects which need to be sorted in a special way:
var sections = [
{begin:"test3", end:"test4"},
{begin:"test5", end:"test2"},
{begin:"test2", end:"test3"},
];
All sections are linked together via sectionA.end == sectionB.begin so the result of the sort operation should be:
var sectionsSorted = [
{begin:"test5", end:"test2"},
{begin:"test2", end:"test3"},
{begin:"test3", end:"test4"}
];
I want to do this in the Array.prototype.sort() method. I realised that the beginning section could be found if the begin is not an end in any section but from there on I am lot. Has anybody an idea how to implement something like this?
I did a JSFiddle: https://jsfiddle.net/fxmnxh8L/1/
begin? Or is there only one order fullfilling the conditions, and you have to serach the correct combination? Is the data guaranteed to contain an unbroken chain of the chainable values?section.begin not in [all sections.end]. Hopefully I described it properly