function getAllSharedNotes(noteStore, maxCount, callback) { var noteFilter = new Evernote.NoteFilter(); noteFilter.words = "sharedate:*"; var sharedNotes = []; var offset = 0; if (!maxCount) { maxCount = 500; } (function _getAllSharedNotes(sharedNotes, offset, maxCount) { if (sharedNotes.length < maxCount) { noteStore.findNotes(noteFilter, offset, 50, function(noteList) { if (noteList.errorCode) { console.log("Error getting shared notes:"); console.log(noteList); return; } sharedNotes = sharedNotes.concat(noteList.notes); if (sharedNotes.length % 50 != 0) { // We've retrieved all of the notes callback(sharedNotes.slice(0, maxCount)); return; } else { offset += 50; _getAllSharedNotes(sharedNotes, offset, maxCount); } }); } else { callback(sharedNotes.slice(0, maxCount)); } })(sharedNotes, offset, maxCount); }