How do I make this average JavaScript function better/more elegant?to calculate the average of an array
I have this function that calculates average. I don't want it to look like this. I am hoping for a less cliche average function. Because because I see that most people's look like this. Can anyone help?
function mean(array) {
var num=0;
for (var i=1;i<=array.length;i++) num=num+array[i];
var divide=num/array.length;
alert(divide);
}
Can anyone change this up to be better than before? It doesn't have to be more efficient but just look better. Thanks! (By the way I'm new to JavaScript so if you can explain your code that'd be great).
I have this function that calculates average. I don't want it to look like this. I am hoping for a less cliche average function. Because I see that most people's look like this. Can anyone help?
function mean(array) {
var num=0;
for (var i=1;i<=array.length;i++) num=num+array[i];
var divide=num/array.length;
alert(divide);
}
Can anyone change this up to be better than before? It doesn't have to be more efficient but just look better. Thanks! (By the way I'm new to JavaScript so if you can explain your code that'd be great).
I have this function that calculates average. I don't want it to look like this. I am hoping for a less cliche average function because I see that most people's look like this.
function mean(array) {
var num=0;
for (var i=1;i<=array.length;i++) num=num+array[i];
var divide=num/array.length;
alert(divide);
}
Can anyone change this up to be better than before? It doesn't have to be more efficient but just look better.
How do I make this average function better/more elegant?
I have this function that calculates average. I don't want it to look like this. I am hoping for a less cliche average function. Because I see that most people's look like this. Can anyone help?
function mean(array) {
var num=0;
for (var i=1;i<=array.length;i++) num=num+array[i];
var divide=num/array.length;
alert(divide);
}
Can anyone change this up to be better than before? It doesn't have to be more efficient but just look better. Thanks! (By the way I'm new to JavaScript so if you can explain your code that'd be great).