How to find an arithmetic sequence in JavaScript: 1. Create a js sample file; 2. Define a print1 function through "function print1(start, value, endKey) {...}"; 3. Through " for (let i = 0; i
The operating environment of this tutorial: Windows 10 system, javascript version 1.8.5, Dell G3 computer.
How to find an arithmetic sequence in JavaScript?
js implements arithmetic sequence
Arithmetic sequence
/** * 等差数列 * start: 开始数字 * value: 差值 * endKey: 结束位置的key */ function print1(start, value, endKey) { let arr = []; for (let i = 0; i < endKey; i++) { arr.push(start + (i * value)); } console.log(arr); } print1(1, 2, 10);
Related expansion:
Arithmetic sequence A sequence refers to a sequence in which starting from the second item, the difference between each item and its previous item is equal to the same constant, often represented by A and P. This constant is called the tolerance of the arithmetic sequence, and the tolerance is often represented by the letter d.
For example: 1,3,5,7,9...2n-1. The general formula is: an=a1 (n-1)*d. The first term a1=1, the tolerance d=2. The sum formula of the first n terms is: Sn=a1*n [n*(n-1)*d]/2 or Sn=[n*(a1 an)]/2. Note: The above n are all positive integers.
Recommended study: "JavaScript Video Tutorial"
The above is the detailed content of How to find an arithmetic sequence in JavaScript. For more information, please follow other related articles on the PHP Chinese website!