How to Get the Average from a JavaScript Array with Functional Programming

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Thank you, I was having trouble understanding the reduce function. Understand it more clearly now.

Ransonikuo
Автор

This was soo helpful! Thank you!
I also love the tip to just pseudocode what you want to do!

MaylynnNg
Автор

Great video! Sorry to ask, but what extension are you using that gives you the results on code?

jayenglishgroup
Автор

Thanks very much for that lesson, i have a question how i can get the average for that exampel : Given an array of countries with their population.
Calculate average population of the countries.

samerlagha
Автор

const arrAvg = arr => arr.reduce((a, b) => a + b) / arr.length
document.write(arrAvg([20, 30, 40]))

saitejagatadi
Автор

Hello, thank you so much for this video. I tried it but I don't have the result in blue in my last lign. Can you help me please ?
const getAverage = arr => {
// sum the values from the array

const reducer = (total, currentValue) => total + currentValue
const sum = arr.reduce(reducer);
// get the length of the array
// divide the array sum by the length
return sum / arr.length;
}
console.log (getAverage ([1, 2, 3, 4, 5])); //?

myriamhelaoui
Автор

I'm begginer, 100% same code wrote, code didn't work. Sadly((

oleksandrtsoi