我们需要编写一个JavaScript函数,该函数接受三个数字作为参数(前两个数字应该是算术级数的前两个连续项)。
第三个数字(例如n)是序列中基于索引的1元素,需要计算其值
例如-
如果输入为2、5、7
那么系列将是-
2, 5, 8, 11, 14, 17, 20
输出应为20。
以下是代码-
const a = 2, b = 5;
const N = 7;
const findNthTerm = (first, second, num) => {
   const diff = second - first;
   const fact = (num - 1) * diff;
   const term = first + fact;
   return term;
};
console.log(findNthTerm(a, b, N));输出结果
以下是控制台中的输出-
20