Files
30-seconds-of-code/snippets/arithmeticProgression.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

610 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
arithmeticProgression math,algorithm,beginner 2020-10-04T11:37:07+03:00 2020-12-28T13:49:24+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, and a map function to fill it with the desired values in the given range.
const arithmeticProgression  = (n, lim) =>
  Array.from({ length: Math.ceil(lim / n) }, (_, i) => (i + 1) * n );
arithmeticProgression(5, 25); // [5, 10, 15, 20, 25]