UNPKG

date-limits

Version:

Check if a date is before a flexible limit.

22 lines (21 loc) 584 B
export function generateSequence(params, limit) { let { slope: a, offset: b = 0 } = params; if (Math.abs(a) === Infinity || Math.abs(b) === Infinity) { throw new Error(`Slope and offset cannot be set to Infinity`); } if (isNaN(a) || isNaN(b)) { return []; } const result = []; b %= a; let x = Math.max(0, Math.ceil(-b / a)); let value = a * x + b; while (value <= limit) { if (value > 0) { result.push(value); } x++; value = a * x + b; } return result; }