There are two arrays of maps. The first array contains maps of ID values in a specific order (but not necessarily either pure ASC or DESC ordering):
// pseudo code
first := [
{"id": 1},
{"id": 2},
{"id": 3}
]
...and an unsorted array of data with corresponding ID values, but not in the same ordering:
second := [
{"id": 3, "text": "hello"},
{"id": 1, "text": "fizz"},
{"id": 2, "text": "bar"}
]
How can I sort the second
array such that its maps are in the same order as the first
array via the matching ID values, while achieving the fastest code execution as possible?
(Note that the ordering of the first
array is not known before runtime.)
The desired result in this case would be:
desiredResult := [
{"id": 1, "text": "fizz"},
{"id": 2, "text": "bar"},
{"id": 3, "text": "hello"}
]