Given n number of arrays A in the format An = [xn, yn, zn] where X, Y, and Z are collections in the format X = [x1, x2, x3, ...xn], Y = [y1, y2, y3, ... yn], and Z = [z1, z2, z3, ...zn], create a function to sort A1 through An such that the sum of the difference between the mean of each collection and it's members is minimized. Arrays may contain null values.
eg. Given arrays A1 = [2, 19, null], A2 = [14, 3, 3], and A3 = [5, 18, 5], we must consider that X = [2, 14, 5], Y = [19, 3, 18], and Z = [null, 3, 5]. Therefore, the mean of X is 7, the mean of Y is 33.3, and the mean of Z is 4. The total delta between the mean of collection X and its members is |7-2| + |7-14| + |7-5| = 14. Likewise the delta of Y is 20.7 and Z is 2. Thus, the total difference between each collection mean and its members is 36.7.
The optimal sort of arrays A1, A2, and A3 will be such that A1 = [19, 2, null], A2 = [14, 3, 3], and A3 = [18, 5, 5]. This minimizes the mean-member collection deltas to 6, 3.3, and 2 respectively or a total delta of 11.3.
