title: sorting columns independently at array level
body: <p>I have a spreadsheet with several columns that I need to sort individually.
  I wrote the script below that works but is a bit slow since it handles each column in turn with <code>getValues()</code> and <code>setValues()</code>.
  I'd like to find a way to do the whole sorting at an array level for more efficiency but I don't know how... any suggestion ?</p>
  
  <p>Here is the relevant part of the code I use now :</p>
  
  <pre><code>...
    sh3.getRange(1,1,1,newData[0].length).setFontWeight('bold');// newData is an array corresponding to the whole sheet
    for(col=1;col&lt;newData[0].length;++col){
      var val = sh3.getRange(2,col,getLastRowInCol(col),1).getValues().sort();// each column have a different height
      sh3.getRange(2,col,getLastRowInCol(col),1).setValues(val)
      }
  }
  
  function getLastRowInCol(col){
    var values = sh3.getRange(2,col,sh3.getLastRow(),1).getValues();// skip header and find last non empty row in column
    for(n=0;n&lt;values.length;++n){
      if(values[n]==''){break}
    }
    return n
  }
  </code></pre>
  
  <p><strong>Note :</strong> <em>I know there is a <a href="https://sites.google.com/site/scriptsexamples/custom-methods/2d-arrays-library" rel="nofollow">Library by Romain Vialard</a> that does the job (sorting columns in 2D arrays) but I'm interrested on how to do it 'manually' for personal JS skills improvement ;-) and also I need to sort every column independently without needing to update the sheet for every column.</em> </p>