@yetnt/ump
Version:
A very useless math package for your complex javascript projects
57 lines • 1.38 kB
JavaScript
;
/**
* f1 : 2a = T1
* f2 : 3a+b = T1
* f3 : a+b+c = T1
*
* final : an^2+bn+c
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Returns singular term.
* @param n The term number (not zero indexed)
* @param a `a`n^2+bn+c
* @param b an^2+`b`n+c
* @param c an^2+bn+`c`
*/
function findTerm(n, a, b, c) {
return a * Math.pow(n, 2) + b * n + c;
}
/**
* Returns multiple terms
* @param n The term number to start at (not zero indexed)
* @param nn The term number to end at
* @param a `a`n^2+bn+c
* @param b an^2+`b`n+c
* @param c an^2+bn+`c`
*/
function findTerms(n, nn, a, b, c) {
let termIndex = n;
const ans = [];
while (termIndex != nn + 1) {
ans.push(a * Math.pow(n, 2) + b * n + c);
n++;
termIndex++;
}
return ans;
}
/**
*
* @param num1 The first number
* @param num2 The second number
* @param num3 The third number
*/
function findNthTerm(num1, num2, num3) {
const p1 = [num2 - num1, num3 - num2];
const p2 = p1[1] - p1[0];
const a = p2 / 2; // 2a = Term 1;
const b = p1[0] - 3 * a; // 3a+b = Term 1
const c = num1 - a - b;
const formula = `(${a}n^2) + (${b}n) + ${c}`;
return { a, b, c, formula };
}
/**
* Quadratic pattern functions
*/
exports.default = { findTerm, findNthTerm, findTerms };
//# sourceMappingURL=QuadraticPattern.js.map