mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
npx standard --fix
This commit is contained in:
@@ -11,20 +11,20 @@
|
||||
https://en.wikipedia.org/wiki/Mean
|
||||
*/
|
||||
|
||||
function mean(nums) {
|
||||
"use strict";
|
||||
var sum = 0;
|
||||
var avg;
|
||||
function mean (nums) {
|
||||
'use strict'
|
||||
var sum = 0
|
||||
var avg
|
||||
|
||||
// This loop sums all values in the 'nums' array.
|
||||
nums.forEach(function (current) {
|
||||
sum += current;
|
||||
});
|
||||
// This loop sums all values in the 'nums' array.
|
||||
nums.forEach(function (current) {
|
||||
sum += current
|
||||
})
|
||||
|
||||
// Divide sum by the length of the 'nums' array.
|
||||
avg = sum / nums.length;
|
||||
return avg;
|
||||
// Divide sum by the length of the 'nums' array.
|
||||
avg = sum / nums.length
|
||||
return avg
|
||||
}
|
||||
|
||||
// Run `mean` Function to find average of a list of numbers.
|
||||
console.log(mean([2, 4, 6, 8, 20, 50, 70]));
|
||||
console.log(mean([2, 4, 6, 8, 20, 50, 70]))
|
||||
|
||||
Reference in New Issue
Block a user