I have been looking for a way to sort an array based on 2 conditions:
First: Sort it based on another array, one being like this: This is the json file to read:
let versiones = ['versionZ', 'versionJ', 'versionA', 'versionK', 'versionC']
If it is not present in the versions array, put them last
Second: Then order it based on its priority present within the elements.
Note: The priority will always exist, it may be that in some cases the key: version does not exist or is shown as null.
Here it would be the array that I want to order without complete success:
[
{ "name": "Juan", "priority": 10, "version": "versionM" },
{ "name": "Manuel", "priority": 5, "version": "versionA" },
{ "name": "Carlos", "priority": 20, "version": "versionJ" },
{ "name": "Raul", "priority": 12, "version": "versionC" }
]