Arithmetic progression

JavaScript, Math, Algorithm · Oct 13, 2021

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.
const arithmeticProgression  = (n, lim) =>
  Array.from({ length: Math.ceil(lim / n) }, (_, i) => (i + 1) * n );
arithmeticProgression(5, 25); // [5, 10, 15, 20, 25]

More like this

  • JavaScript Algorithms

    Learn a handful of popular algorithms, implemented in JavaScript ES6.

    Collection · 35 snippets

  • Geometric progression

    Initializes an array containing the numbers in the specified geometric progression range.

    JavaScript, Math · Dec 28, 2020

  • Powerset

    Returns the powerset of a given array of numbers.

    JavaScript, Math · Sep 27, 2021

  • Primes up to given number

    Generates primes up to a given number, using the Sieve of Eratosthenes.

    JavaScript, Math · Dec 28, 2020