UNPKG

@yetnt/ump

Version:

A very useless math package for your complex javascript projects

50 lines 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * * @param n The term number (not zero indexed) * @param a The first term * @param r The constant ratio. */ function findTerm(n, a, r) { return a * Math.pow(r, n - 1); } /** * * @param n The term number (not zero indexed) * @param nn * @param a The first term * @param r The constant ratio. */ function findTerms(n, nn, a, r) { let termIndex = n; const ans = []; while (termIndex != nn + 1) { ans.push(a * Math.pow(r, n - 1)); 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 nums = [num1, num2, num3]; const r = nums[1] / nums[0]; const rCheck = nums[2] / nums[1]; if (r !== rCheck) { throw new Error("Pattern is not a geometric pattern."); } const a = num1; const formula = `${a} * ${r}^(n - 1)`; return { a, r, formula }; } /** * Gemotric pattern functions */ exports.default = { findTerm, findTerms, findNthTerm }; //# sourceMappingURL=GeometricPattern.js.map