I have an array of
double[] weights = { 32.0, 32.0, 25.0, 25.0, 30.0, 28.0,
12.0, 10.0, 8.0, 8.0, 18.0, 0.0 };
I want to sort its corresponding indices 0 through 11 according to a descending sort of weights:
{ 32.0, 32.0, 30.0, 28.0, 25.0, 25.0, 18.0, 12.0, 10.0, 8.0, 8.0, 0.0 }
My desired output, in this case, would be an int[]:
{ 0, 1, 4, 5, 2, 3, 10, 6, 7, 8, 9, 11 }
I have added an int[] values to keep track of indices:
int[] values = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }
weights.zipWithIndex.sortBy(-_._1).map(_._2). There is a library that provides similar abstractions for Java. You can use that.