I kinda want to create a feature which is most often known in factories. Kind of rotation system, where people swap their station, while others are on break.
via DragnDrop I create/add/update a Map and convert this map to an array of arrays like this:
let example1 = [
['John', ['99', '1']],
['Jo', ["1", "3"]],
["Alpha", ["99", "4"]],
["Beta", ["3", "2"]],
["Gamma", ["2", "99"]],
["Delta", ["4", "5"]],
["Maria", ["5", "6"]],
["Epsilon", ["6", "99"]],
];
the first number is for the old Position, the second number is for the new position. The number 99 stands for beeing on break. the output for above example should be something like:
outputExample1 = [
["John", "1", "3", "2"],
["Alpha", "4, "5", "6"]
]
so every sequenze and recursion should start with a breaker (=number 99) and end with a breaker. in above example: after placing "john" at station one, it should "search" where the guy/ladie from station 1 is "now". in this example, he is on 3. now search again where the one from statin 3 is now. (=2) ... until the number is 99, which is the case at this example. thats why I started to filter the original array in 'activ'(<99) and 'breakers'(==99). I tried so many ways and fail continously ( while loops ends in an endless loop, outputs which are totally wrong), because i dont find a nice recursion.
Any hints are very preciated
PS: please consider that above array is "finished" to provide a good example and may not be completed on the fly (via drag and drop). Meaning: if I start to drag the sequenze is for sure not completed.
Edit: there will be for sure at least ONE '99'. if not no sequenze and no output. Also there are no duplicates on the 'new position' except 99er. (which are the starters anyway
99? Are the sequences allowed to diverge, i.e. can there be duplicates in the positions? What is the expected output in these cases?