/* Sort 2D array by column PASS: theArray (a 2D array), sortColumn(the column to sort by), sortAsString (if true, converts the value to a string before comparing) RETURNS: theArray, sorted by the column specified */ function sort2DArray (theArray, sortColumn, sortAsString = false) { theArray = theArray.sort(function(x,y){ if (sortAsString) { var xp = x[sortColumn].toString(); var yp = y[sortColumn].toString(); } else { var xp = x[sortColumn]; var yp = y[sortColumn]; } return xp == yp ? 0 : xp < yp ? -1 : 1; }); return theArray; }