How to sort a list by two values?

45 Views Asked by At

I need help with a sorting algorithm.

I have a list of foods. Each food has 2 nutrients.

enter image description here

I want to sort this list in a way in which, at the top should be the foods that has the greatest N High nutrient, but at the same time, the lowest N Low nutrient. The priority is N High, but N Low matters too. Look at that example. If only we would sort by N High, then Food 2 will be the first and Food 3 will be the second. But also taking into account N Low, the foods swich places, because it is better to have a food with 27g less from the unwanted nutrient N Low, at the expense of only 8g from the good nutrient N High. I don't know if I explained well...

I know how to sort the list, but I need only one value made from those two nutrients... and I don't know how to do that.

Thanks !