I have two arrays,
A = [green, blue, red];
B = [2, 1, 0]
I want to change the order of A to be in [red, blue, green]. The changes are based on the value of B Below is what I have tried,
arrangeValues();
function arrangeValues() {
A.sort((a,b)=>{
let orderA:any=B.indexOf(a.value);
let orderB:any=B.indexOf(b.value);
if (orderA==-1)
orderA=99999;
if (orderB==-1)
orderB=99999;
return orderB-orderA
})
}
Balways the same length asAand made up of consecutive numbers starting at 0?