title: How to sort list of data in a sheet based on custom algorithm?
body: <p>I have attached some code which attempts to do this, but I am having difficulty returning the array to the sheet. The data is formatted as below.
  [1]: <a href="https://i.stack.imgur.com/6H6jF.png" rel="nofollow noreferrer">https://i.stack.imgur.com/6H6jF.png</a>
  With the other columns, it is simple to just call SpreadsheetApp.getActiveSpreadsheet().sort(#);
  However, With this, essentially I want to maintain the order of the list, except any value with &quot;Seen&quot; in the fourth column is put to the end. I attempted this with:</p>
  <pre><code>function sortProgress() {
    var sheet = SpreadsheetApp.getActiveSpreadsheet();
    var output = [];
    var i = 0;
    while (sheet[i] != null) {
      if (sheet[i][4] != &quot;Seen&quot;) {
        output.push(sheet[i]);
      }
      i++;
    }
    i = 0;
    while (sheet[i] != null) {
      if (sheet[i][4] == &quot;Seen&quot;) {
        output.push(sheet[i]);
      }
      i++;
    }
    sheet.getRange(&quot;A1:A20&quot;).setValues(output);
  }
  </code></pre>
  <p>But I didn't know how to actually display this to the google spreadsheet. Any tips would be greatly appreciated.</p>