How to find an arithmetic sequence in JavaScript

藏色散人
Release: 2023-02-10 09:56:42
Original
2367 people have browsed it

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

How to find an arithmetic sequence in JavaScript

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);
Copy after login

How to find an arithmetic sequence in JavaScript

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.

How to find an arithmetic sequence in JavaScript

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template