title: Google Script - Calendar events not owned by me
body: <p>I'm trying to write a script to delete event invites from my personal google calendar. I get invited to multiple events everyday such as "Click here to win an iPhone" etc.</p>
  
  <p>I have written a google script to run each hour and delete any events where I am not the owner. However this is getting all events and then iterating through them to see if I am the owner in a for loop. This seems quite inefficient and takes a long time to run.</p>
  
  <p>Is there a better way to achieve this.</p>
  
  <p>Current code below:</p>
  
  <pre><code>function deleteScamCalendarInvites() {
  
    var date = new Date();
    var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
    var lastDay = new Date(date.getFullYear() + 5, date.getMonth(), 1);
  
    var myCalendar = CalendarApp.getDefaultCalendar();
    var myEvents = myCalendar.getEvents(firstDay, lastDay);
  
    for(var i in myEvents){
      if(myEvents[i].isOwnedByMe() == false){
         var eventId = myEvents[i];
         eventId.deleteEvent();
      }
    }
  }
  </code></pre>