Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JavaScript var a = [10,8,12,17,18]; var total = 0; for(var i = 0; i < a.length; i++) { total += a[i]; } var avg =

JavaScript

var a = [10,8,12,17,18];

var total = 0;

for(var i = 0; i < a.length; i++) { total += a[i];

}

var avg = total / a.length;

console.log("total=" + total + " average="+ avg);

Refactor the above problem and define a function named stats which takes in an array as the 1st and only parameter and returns a string with the same result as the above problem. Run it this way: console.log( stats( [2,4,6,8,10] ) );

DO NOT LOG the output in the function, return the result from the function, the console will print it if it is the list thing or use console.log( on the function )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago

Question

Write short notes on Marketing mix.

Answered: 1 week ago