Array sum

JavaScript, Math · Oct 22, 2020

Calculates the sum of two or more numbers/arrays.

const sum = (...arr) => [...arr].reduce((acc, val) => acc + val, 0);

sum(1, 2, 3, 4); // 10
sum(...[1, 2, 3, 4]); // 10

More like this

  • Greatest common divisor

    Calculates the greatest common divisor between two or more numbers/arrays.

    JavaScript, Math · Dec 29, 2020

  • Mapped array sum

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

    JavaScript, Math · Nov 3, 2020

  • Product of numeric values

    Calculates the product of two or more numbers/arrays.

    JavaScript, Math · Oct 22, 2020