I have two arrays, both of objects.
Charities (unordered):
[{
"_id": "5527c2b29a4c7ebe2953129d",
"name": "Lorem ipsum",
"number": 1,
"metric": "Lorem ipsum",
"metricConversion": 6,
"logo": "http://api.fake.net/example.png",
"country": "Albania",
"twitter": "exampletwitter",
"facebook": "examplefb"
}, ...]
Promotions:
[{
"type": 1,
"charity": "5527c2b29a4c7ebe2953129d",
"start": Sun May 10 2015 14:11:32 GMT+0100 (BST),
"end": Thu Jul 02 2009 00:00:00 GMT+0100 (BST),
"priority": 10
}, ...]
The promotions array is ordered by the priority (greatest first).
What I am trying to do is order the charities array by the promotions array, so the charity with the highest value for priority is put first, etc (with the connection being _id to charity).
I can think of several easy ways to do this, however the ones that come to mind are very inefficient. Any suggestions?