const arrAvg = arr => arr.reduce((a,b) => a + b, 0) / arr.length
function avg(arr){
let additions = 0;
for(let index=0; index<arr.length; index++){
additions += arr[index];
}
return (additions/arr.length);
}
const average = (...args) => args.reduce((a, b) => a + b) / args.length;
average(1, 2, 3, 4);
// Result: 2.5
var sum = array.reduce((a, b) => a + b, 0); //get sum of all elements in array
var avg = (sum / array.length) || 0; //get average of all elements in array ;)
const sum = times.reduce((a, b) => a + b, 0);
const avg = (sum / times.length) || 0;
console.log(`The sum is: ${sum}. The average is: ${avg}.`);
let output = []
for(let i = 0; i < input[0].length; i++)
{
let firstName = input[0][i];
let lastName = input[1][i];
let dateBirth = input[2][i];
if(dateBirth < 10)
{
dateBirth = `0${dateBirth}`;
}
let birthMonth = `${input[3][i][0]}${input[3][i][1]}${input[3][i][2]}`
let birth = `${dateBirth}/${birthMonth}/${input[4][i]}`
let age = 2021 - input[4][i]
output.push(`${firstName} ${lastName} - ${birth} - ${age} Tahun`)
}
return output;
}
const arr = [5,10,15,20,25];
arr.reduce(function(x,y){
sum = x+y;
mean = sum/arr.length;
return sum;
},
0);
console.log(mean);//15