Due to badly written code. I have to sort an array and base on that sorting, sort another array in the same order. E.g:
foo =[ ['tom', 20, {teacher: 'may', class: 'math'}],
['Ann', 21, {teacher: 'Joe', class: 'CS'}],
['tony', 22, {teacher: 'may', class: 'math'}]
]
bar = [{extraPara: 'ran1', Sequence 2},
{extraPara: 'ran2', Sequence 1},
{extraPara: 'ran3', Sequence 3},
]
I want to sort bar with Sequence. And I want to sort foo base on that sequence too. Basically both array should be in one big array, but because of bad coding, it is separated. However I do not have time to re write the whole structure.
What is the most efficient way to do this?
I can easily sort bar by:
bar = _.sortBy(bar, function(item) {return item.Sequence})
The only way I know how to do it is write the sorting algorithm myself, and whenever I change the ordering of bar I will use the index and do the same for foo. However that sounds very inefficient and readability is really bad
any tips?