Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a function that accepts an array of numbers and returns the sum of all

ID: 3881965 • Letter: I

Question

Implement a function that accepts an array of numbers and returns the sum of all the numbers in the list. Your implementation must use the Array.reduce function internally.

sum([-5, 3, -10]); // returns -12 Implement a function that accepts an array of numbers and returns the sum of all the numbers in the list. Your implementation must use the Array.reduce function internally.

sum([-5, 3, -10]); // returns -12 Implement a function that accepts an array of numbers and returns the sum of all the numbers in the list. Your implementation must use the Array.reduce function internally.

sum([-5, 3, -10]); // returns -12 sum([-5, 3, -10]); // returns -12

Explanation / Answer

<html>
   <head>
       <script>

          
                        function sum(total, n)
                        {
                                return total + n;
                        }
  
            var arrayOfNumber=[-5,3,-10] ;
          
           function sumOfNumbers(array)
           {
               var total = array.reduce(sum);
               alert('Input numbers are '+array +' and sum is '+total) ;
           }
          
           function test()
           {  

                            // passing array to function
                            sumOfNumbers(arrayOfNumber) ;
           }
       </script>
   </head>

   <body>
       <button type="button"> Click Me</button>
   </body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote