code: function pickMostDue(s, state) {
    var prec = ['learning', 'overdue', 'due'];
    for (var i = 0; i < prec.length; i += 1) {
      var sched = prec[i];
      if (s[sched].length) {
        return s[sched].slice(0).sort(function (a, b) {
          var cardA = state.cardStates[a];
          var cardB = state.cardStates[b];
          if (cardA == null) {
            throw new Error('id not found in state: ' + a);
          }
          if (cardB == null) {
            throw new Error('id not found in state: ' + b);
          }
  
          var reviewDiff = cardA.lastReviewed == null && cardB.lastReviewed != null ? 1 : cardB.lastReviewed == null && cardA.lastReviewed != null ? -1 : cardA.lastReviewed == null && cardB.lastReviewed == null ? 0 : cardB.lastReviewed - cardA.lastReviewed;
          if (reviewDiff !== 0) {
            return -reviewDiff;
          }
  
          if (a === b) {
            throw new Error('comparing duplicate id: ' + a);
          }
          return b > a ? 1 : -1;
        })[0];
      }
    }
    return null;
  }
docs: Breaks ties first by last review (earlier beats later), then by an alphabetical comparison of the cardId (just so it stays 100% deterministic)  Returns null if no cards are due.