Javascript/Math: editing file name

This commit is contained in:
itsvinayak
2020-05-06 18:30:19 +05:30
parent ba75297f72
commit 75f6888019
24 changed files with 0 additions and 0 deletions

30
Maths/AverageMean.js Normal file
View File

@ -0,0 +1,30 @@
/*
author: PatOnTheBack
license: GPL-3.0 or later
Modified from:
https://github.com/TheAlgorithms/Python/blob/master/maths/average.py
This script will find the average (mean) of an array of numbers.
More about mean:
https://en.wikipedia.org/wiki/Mean
*/
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
})
// 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]))