In my current function, I am able to sort an array alphabetically.
function compare(a,b) {
if (a.subtitle < b.subtitle)
return -1;
if (a.subtitle > b.subtitle)
return 1;
return 0;
}
Now, I am in need of a similar function that will allow me to sort the array based on another array. Despite my attempts to write this function myself, I was unable to figure it out and ended up with nothing.
For example:
I want Array1 to be sorted according to its position in Array2.
Array1 = ['quick','fox','the','brown'];
Array2 = ['the','quick','brown','fox'];
It seems like there should be a simple solution to this problem that I'm just not seeing.
Edit:
In addition, any items present in Array1 that are not in Array2 can simply be added to the end without any specific order or alphabetization for simplicity's sake.