Fibonacci

JavaScript, Math, Algorithm · Dec 28, 2020

Generates an array, containing the Fibonacci sequence, up until the nth term.

const fibonacci = n =>
  Array.from({ length: n }).reduce(
    (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
    []
  );
fibonacci(6); // [0, 1, 1, 2, 3, 5]

More like this

  • Geometric progression

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

    JavaScript, Math · Dec 28, 2020

  • Primes up to given number

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

    JavaScript, Math · Dec 28, 2020

  • Arithmetic progression

    Creates an array of numbers in the arithmetic progression, starting with the given positive integer and up to the specified limit.

    JavaScript, Math · Oct 13, 2021