I have multiple arrays:
I need to sort the arrays by their length. Eg:
How to find out which one is the largest, the second largest, the third largest, and the least array?
I have multiple arrays:
I need to sort the arrays by their length. Eg:
How to find out which one is the largest, the second largest, the third largest, and the least array?
You can do it like this:
import System.Linq;
import System.Collections.Generic;
var arrays = new List.<Array>();
arrays.Add(arr_a);
arrays.Add(arr_b);
arrays.Add(arr_c);
arrays.Add(arr_d);
var sortedArrays = arrays.OrderBy(function(a) { return a.length; }).ToList();
var shortestArray = sortedArrays[0];
var nextShortest = sortedArrays[1];
I have to say using Array is not a good idea in Unity Script - there are a lot of better collection classes (like the ones I’ve used here). You should use a strongly typed collection where possible or a List implementation.