jsdataframe.js
function argSort(vectors, ascending) {
  if (vectors.length !== ascending.length) {
    throw new Error('length of "ascending" must match the number of ' +
      'sort columns');
  }
  if (vectors.length === 0) {
    return null;
  }
  var nRow = vectors[0].size();
  var result = allocArray(nRow);
  for (var i = 0; i < nRow; i++) {
    result[i] = i;
  }

  // Create composite compare function
  var compareFuncs = ascending.map(function(asc) {
    return asc ? compare : compareReverse;
  });
  var compositeCompare = function(a, b) {
    var result = 0;
    for (var i = 0; i < compareFuncs.length; i++) {
      var aValue = vectors[i].values[a];
      var bValue = vectors[i].values[b];
      result = compareFuncs[i](aValue, bValue);
      if (result !== 0) {
        return result;
      }
    }
    // Order based on row index as last resort to ensure stable sorting
    return compare(a, b);
  };

  result.sort(compositeCompare);
  return result;
}
function argSort(vectors, ascending) {
  if (vectors.length !== ascending.length) {
    throw new Error('length of "ascending" must match the number of ' +
      'sort columns');
  }
  if (vectors.length === 0) {
    return null;
  }
  var nRow = vectors[0].size();
  var result = allocArray(nRow);
  for (var i = 0; i < nRow; i++) {
    result[i] = i;
  }

  // Create composite compare function
  var compareFuncs = ascending.map(function(asc) {
    return asc ? compare : compareReverse;
  });
  var compositeCompare = function(a, b) {
    var result = 0;
    for (var i = 0; i < compareFuncs.length; i++) {
      var aValue = vectors[i].values[a];
      var bValue = vectors[i].values[b];
      result = compareFuncs[i](aValue, bValue);
      if (result !== 0) {
        return result;
      }
    }
    // Order based on row index as last resort to ensure stable sorting
    return compare(a, b);
  };

  result.sort(compositeCompare);
  return result;
}
function argSort ( vectors , ascending ) { if ( vectors . length !== ascending . length ) { throw new Error ( 'length of "ascending" must match the number of ' + 'sort columns' ) ; } if ( vectors . length === 0 ) { return null ; } var nRow = vectors [ 0 ] . size ( ) ; var result = allocArray ( nRow ) ; for ( var i = 0 ; i < nRow ; i ++ ) { result [ i ] = i ; } // Create composite compare function var compareFuncs = ascending . map ( function ( asc ) { return asc ? compare : compareReverse ; } ) ; var compositeCompare = function ( a , b ) { var result = 0 ; for ( var i = 0 ; i < compareFuncs . length ; i ++ ) { var aValue = vectors [ i ] . values [ a ] ; var bValue = vectors [ i ] . values [ b ] ; result = compareFuncs [ i ] ( aValue , bValue ) ; if ( result !== 0 ) { return result ; } } // Order based on row index as last resort to ensure stable sorting return compare ( a , b ) ; } ; result . sort ( compositeCompare ) ; return result ; }
Returns an array of integer indices that would sort the given array of vectors, starting with the first vector, then the second, etc. "ascending" must be an array of booleans with the same length as "vectors". Returns null if "vectors" is empty.
Returns an array of integer indices that would sort the given array of vectors starting with the first vector then the second etc . ascending must be an array of booleans with the same length as vectors . Returns null if vectors is empty .