I have a Map object that looks like so:
const myMap = new Map();
myMap.set('a', 1);
myMap.set('b', 2);
myMap.set('c', 3);
myMap.set('d', 4);
I would need to be able to reorder that, so that, having a specific key, this key would be first, those keys originally following it should follow as before, and those originally preceding it will be placed at the end with their original order.
An example with arrays:
const key = 'c';
const pre = ['a','b','c','d'];
const post = ['c','d','a','b'];
Another example:
const key = 'd';
const pre = ['a','b','c','d'];
const post = ['d','a','b','c'];
Yet another:
const key = 'a';
const pre = ['a','b','c','d'];
const post = ['a','b','c','d'];
I guess I should take the keys with myMap.keys()
and rebuild my map, buy my brain is really struggling to find out how to deal with it to achieve what I want....
Any hints would be greatly appreciated.