Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Using Array.reduce() method

// define a reusable function
const calculateSum = (arr) => {
    return arr.reduce((total, current) => {
        return total + current;
    }, 0);
}

// try it
console.log(calculateSum([1, 2, 3, 4, 5]));
Source by www.kindacode.com #
 
PREVIOUS NEXT
Tagged: #Using #method
ADD COMMENT
Topic
Name
6+3 =