Files
30-seconds-of-code/js/snippets/arithmetic-progression.md
2023-05-03 20:39:23 +03:00

21 lines
602 B
Markdown

---
title: Arithmetic progression
type: snippet
tags: [math,algorithm]
cover: u-got-this
dateModified: 2021-10-13T19:29:39+02:00
---
Creates 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`. Use 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) }, (_, i) => (i + 1) * n );
```
```js
arithmeticProgression(5, 25); // [5, 10, 15, 20, 25]
```