Product of numeric values

Isabelle Viktoria Maciohsek · JavaScript, Math, Array · Oct 22, 2020

Calculates the product of two or more numbers/arrays.

const prod = (...arr) => [...arr].reduce((acc, val) => acc * val, 1);
prod(1, 2, 3, 4); // 24
prod(...[1, 2, 3, 4]); // 24

Recommended snippets

  • Cartesian product

    JavaScript, Math

    Calculates the cartesian product of two arrays.

  • Array sum

    JavaScript, Math

    Calculates the sum of two or more numbers/arrays.

  • Mapped array average

    JavaScript, Math

    Calculates the average of an array, after mapping each element to a value using the provided function.