UNPKG

@flasd/spaced-repetition

Version:
2 lines (1 loc) 1.03 kB
var t=864e5,e=function(t){void 0===t&&(t={}),this.options={debug:t.debug,nowFn:t.nowFn},this.getDueCards=this.getDueCards.bind(this)};e.prototype.getDay=function(t){void 0===t&&(t={forDate:Date.now()});var e=t.forDate;try{"function"==typeof this.options.nowFn&&(e=this.options.nowFn())}catch(t){this.options.debug&&console.error(t)}return Math.floor(e/864e5)},e.prototype.computeNextRepetition=function(t){if(0===t.length)return this.getDay()-1;var e=t[t.length-1],n=this.getDay({forDate:e.timestamp});if(e.difficulty>=3){if(1===t.length)return n+1;if(2===t.length)return n+6;var r=2.5;return t.forEach(function(t){r+=+(.1-(4-t.difficulty)*(.08+.02*(4-t.difficulty)))}),r<1.3&&(r=1.3),n+Math.ceil(t.length*r)}return n},e.prototype.getDueCards=function(t,e){var n=this,r=this.getDay();return t.map(function(t){var r=e.filter(function(e){return e.card===t.id});return[t,n.computeNextRepetition(r)]}).filter(function(t){return t[1]<=r})};var n=(new e).getDueCards;export{t as DAY_IN_MILLISECONDS,e as SpacedRepetition,n as getDueCards};