function calc (P, PMT, r, n, t) { const rn = (r / 100) / n const nt = n * t const pn = 12 / n const principal = P * Math.pow(1 + rn, nt) const series = PMT * (pn * (Math.pow(1 + rn, nt) - 1) / rn) return parseInt(principal + series, 10) } module.exports = opts => { if (typeof opts !== 'object') { throw new Error(`Expected 'opts' to be an object, received ${typeof opts}.`) } return calc( opts.initial, opts.monthly, opts.interest, opts.compound, opts.years ) } module.exports.verbose = opts => { if (typeof opts !== 'object') { throw new Error(`Expected 'opts' to be an object, received ${typeof opts}.`) } return Array(opts.years + 1) .fill(null) .map((x, idx) => calc( opts.initial, opts.monthly, opts.interest, opts.compound, idx ) ) }