Sorting Nearest Numbers by using array

arrays, c#, sorting

Solution

var result = array.OrderBy(i => Math.Abs(i - value))
             .ThenBy(i => i < value)
             .ToArray();

Problem

There is an array ``` int[] array = new int[]{6,4,10,7,7,9}; ``` and a number 8. I wanna sort the array around 8 by nearest number. the nearest numbers : 9,7,7,10,6,4 respectively because 9-1 = 8, 7+1 = 8, 7+1 = 8, 10-2 = 8, 6+2 = 8, 4+4 = 8 how can I sort this numbers. any idea?

Original source

Related problems