Merge pull request #1267 from 30-seconds/arithmetic-progression

Add arithmeticProgression
This commit is contained in:
Angelos Chalaris
2020-10-04 11:57:31 +03:00
committed by GitHub

View File

@ -0,0 +1,17 @@
---
title: arithmeticProgression
tags: math,array,beginner
---
Returns an array of numbers in the arithmetic progression starting with the given positive integer and up to the specified limit.
- Use `Array.from()` to create an array of the desired length, `lim/n`, and a map function to fill it with the desired values in the given range.
```js
const arithmeticProgression = (n, lim) =>
Array.from({ length: Math.ceil(lim / n) }, (v, i) => (i + 1) * n );
```
```js
arithmeticProgression(5, 25); // [5, 10, 15, 20, 25]
```