Skip to content

Latest commit

 

History

History
34 lines (21 loc) · 1.15 KB

arithmetic-progression.md

File metadata and controls

34 lines (21 loc) · 1.15 KB
标题 标签
arithmeticProgression(倍数连续数字数组) math,beginner(数学,初学者)

从创建一个倍数连续数字数组,从给定的正整数开始,直至指定的限制。

  • 使用Array.from()创建所需长度,limit / n的数组,并使用map函数在给定范围内填充所需值。

代码如下:

const arithmeticProgression = (n, limit) =>
  Array.from({ length: Math.ceil(limit / n) }, (_, i) => (i + 1) * n);

ts代码如下:

调用方式:

arithmeticProgression(5, 25); // [5, 10, 15, 20, 25]

应用场景

以下是一个实战示例:

结果如下:

<iframe src="codes/javascript/html/arithmetic-progression.html"></iframe>