title: Copy and return modified range in a function
body: <p>My scenario is this: i want to write a function which can remove the 3 lowest element from a range, and returns the modified range to be processed in Google Spreadsheets. I'm totally new to Google App scripts, so my very bad code is here:</p>
  
  <pre><code>function removeWorse(range, n) {
  
    var data = [];
  
    for(var i = 1; i &lt;= range.getNumColumns(); i++) {
      data.push(range.getCell(1, i).getValue());
    }
    data.sort();
  
    var range2;
    range.copyTo(range2);
  
    for(var i = data.length - 1; i &gt;=n; i--) {
      range2.getCell(1, i).setValue(data[i]);
      Logger.log(2);
    }
  
    return range2;
  
  }
  </code></pre>
  
  <p>It gets stuck in line 11: <code>copyTo</code> does not exist.</p>
  
  <p>How can i modify this code to actually do my task? :)</p>