Lets say we have input: var myList = new List<int>(){ 100, 85, -200, -75, 50 }
How would you sort this based on absolute values and get a sorted list based on the absolute values while still keeping the original values?
So the desired output would look like this: {-200, 100, 85, -75, 50}
I get that you can use Math.abs()
to get the absolute values and then sort it, but i want to keep the original values. (Knowing whether it is a negative/positive is of importance.)